post请求返回html结果,VC里的http post请求返回数据比html慢很多,帮忙看下,谢谢...

本文探讨了两个HTTP请求的响应速度差异,一个是快速返回结果的POST请求,另一个是返回很慢的POST请求。通过C++的CHttpAPI实现详细展示了请求过程,并指出ReadString函数在处理大容量数据时可能出现的延迟问题。博客着重于HTTP请求的性能分析及可能的优化策略。
摘要由CSDN通过智能技术生成

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左右

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值