64,683
社区成员
发帖
与我相关
我的任务
分享
LRESULT Cnotify15Dlg::QueryMessage(void) //询问是否有新消息
{
CInternetSession m_InetSession(_T("session"),
0,
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
INTERNET_FLAG_DONT_CACHE); //设置不缓冲
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
CString strHtml = _T("");
CString strHtml1 = _T("");
CString strRequest = _T("viewID=&isGuest=false&userAccount="+m_edit1+"&userpassword="+m_edit2); //POST过去的数据
//CString strRequest = _T("userAccount="+m_edit1+"&userpassword="+m_edit2); //POST过去的数据
CString strRequest1 = _T("page=1&rows=10");
//以下为登录数据包
CString strHeaders = _T("Host: 192.168.10.13:6606/logined\r\n"
"Connection: keep-alive\r\n"
"Cache-Control: max-age=0\r\n"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n"
"Origin: http://192.168.10.13:6606\r\n"
"User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1500.107 Safari/537.36\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Referer: http://192.168.10.13:6606/login\r\n"
"Accept-Encoding: gzip,deflate,sdch\r\n"
"Accept-Language: zh-CN,zh;q=0.8");
INTERNET_PORT nPort; //端口
nPort=6606;
CString strCookieData;
LPSTR lpszData = NULL;
pServer = m_InetSession.GetHttpConnection(_T("192.168.10.13"), nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,_T("/logined"),NULL,1,NULL,_T("HTTP/1.1"),INTERNET_FLAG_RELOAD);
if(m_flag5==0) //只需发一次数据包去登录
{
pFile->AddRequestHeaders(strHeaders);
pFile->SendRequestEx(strRequest.GetLength());
pFile->WriteString(strRequest);
pFile->EndRequest();
}
m_flag5=1;
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
CString strLine=NULL;
strLine.Empty();
CString m_strCookies;
LPCSTR pszURL=("http://192.168.10.13:6606/getNewMessages");
// DWORD dwServiceType;
CString strServer;
CString strObject;
//查询消息的窗口
pFile=pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,_T("/getNewMessages"),NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
pFile->SendRequest();
strHtml1="";
int nRead;
while ((nRead = pFile->ReadString(strLine))>0) //这里出错,ReadString的值老是不变
{
//::MessageBox(NULL,"DD","DD",MB_OK);
std:: wstring str1= UTF8ToUnicode((LPCSTR)strLine);
::MessageBoxW(NULL,str1.c_str(),L"cc",MB_OK);
strHtml1 += strLine;
}
delete pFile;
delete pServer;
m_InetSession.Close();
return TRUE;
}