首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

请问下http post请求获取数据和html比起来那么慢,帮忙看下,多谢

2012-01-19 
请教下http post请求获取数据和html比起来那么慢,帮忙看下,谢谢html:请求,很快返回结果POST /index.php HT

请教下http post请求获取数据和html比起来那么慢,帮忙看下,谢谢
html:请求,很快返回结果
POST /index.php HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: 127.0.0.1
Content-Length: 56
Connection: Keep-Alive
Cache-Control: no-cache

AC=RecvCommand&UserID=446233&Key=xxx&Submit=%CC%E1%BD%BB


C++:请求,返回结果很慢

POST /index.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Accept: */*
User-Agent: CHttpAPI
Host: 127.0.0.1
Content-Length: 56
Cache-Control: no-cache

AC=RecvCommand&UserID=446233&Key=xxx&Submit=%CC%E1%BD%BB

C++的方法:
CInternetSession Session;  
CHttpConnection* pConn=NULL;

pConn = Session.GetHttpConnection(strServerName,nPort);  
pFile = pConn->OpenRequest(0,strObject,NULL,1,NULL,"HTTP/1.1",INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_NO_AUTO_REDIRECT);  
pFile->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");  
pFile->AddRequestHeaders("Accept: */*");  
pFile->SendRequest(NULL,0,outBuff,strlen(outBuff));  
pFile->QueryInfoStatusCode(retcode);  

CString text;  
for(int i=0;pFile->ReadString(text);i++)  
{  
  HttpReturn=HttpReturn+text+"\r\n";  
}  
pFile->Close();  

ReadString这个函数很久才返回。。我使用Read测试过,Read读取的有时候很久才返回,不知道什么原因,数据大概6K左右

[解决办法]
我用的时候没有感觉,说话你的目标是要获取网页的代码吗?
[解决办法]
Connection:close试一下
[解决办法]
CHttpFile::Read试试
[解决办法]
数据很多吗? 第一个请求表明允许返回压缩数据哦, 服务器是不是第一种情况进行了GZip压缩?

Accept-Encoding: gzip, deflate

热点排行