求救,使用WININET向网站读取简单数据,返回值老是不变

aerfaxing 2014-05-06 06:55:37
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;
}


求解啊,这里使用WININET是不是哪里出错了,在WIN7上实验没事,但在XP上读取192.168.10.13:6606/getNewMessages的数据,却老是出错,我这个函数每40秒调用一次,第一次取回来的值是正常的,之后第二次,第三次,第N此读取的值都是跟第一次相同,我可以保证192.168.10.13:6606/getNewMessages的值在第一次以后是变化了的!
...全文
97 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
aerfaxing 2014-05-06
  • 打赏
  • 举报
回复
同志们,江湖救急啊
aerfaxing 2014-05-06
  • 打赏
  • 举报
回复
没同志遇到这种奇葩问题么
aerfaxing 2014-05-06
  • 打赏
  • 举报
回复
自顶,求高手解答

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧