VC模拟http请求,错误码10054

u010975775 2013-11-13 06:20:06
近期做MFC程序,内部有一个模拟http请求模块,几千的客户使用没有问题,昨天突然有个用户出了问题。
情况如下:在把http协议的head和body数据组装好了,并且发送成功了,可是接下来在接受的时候发生错误,返回码为10054。

代码如下:
	if (!strHttpProtocol.IsEmpty())
{
//MessageBox(hwnd,"开始发送","1",MB_OK);
//int nBytes = send(sockClient, strHttpProtocol, strHttpProtocol.GetLength(), 0);
if (send(sockClient, strHttpProtocol, strHttpProtocol.GetLength(), 0) == SOCKET_ERROR)
{
//MessageBox(hwnd,"发送失败","1",MB_OK);
closesocket(sockClient); //关闭TCP套接字
WSACleanup(); //释放winsock库
return strRSAKey;
}

}
else
{
closesocket(sockClient); //关闭TCP套接字
WSACleanup(); //释放winsock库
return strRSAKey;
}

//MessageBox(pPassWord->GetSafeHwnd(),"发送成功","1",MB_OK);
int nRetBytes = 0;
try
{
CString strRec;
CString strContent;
strContent.Empty();
int nContentLen = 0;
while (1)
{
nRetBytes = recv(sockClient,strRecvData,10240,0);//获取返回信息
//MessageBox(pPassWord->GetSafeHwnd(),strRecvData,"pos返回数据",MB_OK);
if(nRetBytes == SOCKET_ERROR || nRetBytes == 0)
{
int nCode = GetLastError();
CString strError;
strError.Format("错误码%d", nCode);
WriteLog(strError);
closesocket(sockClient); //关闭TCP套接字
WSACleanup(); //释放winsock库
return strRSAKey;
}
else
{
strRec = strRecvData;
strRec = strRec.Right(strRec.GetLength() - strRec.Find(_T("Content-Length:")) - strlen(_T("Content-Length:")) -1);
//MessageBox(pPassWord->GetSafeHwnd(),strRec,"pos返回数据",MB_OK);
nContentLen = atoi(strRec.Left(strRec.Find(_T("\r\n"))));

strContent += strRec.Right(strRec.GetLength() - strRec.Find(_T("\r\n\r\n")) - 4);
//MessageBox(pPassWord->GetSafeHwnd(),strContent,"pos返回数据",MB_OK);
if (strContent.GetLength() >= nContentLen)
{
break;
}

}

}
}



http协议如下:
POST /main/index.php HTTP/1.1

Accept: */*

Accept-Language: zh-cn

Cache-Control: no-cache

Connection: Keep-alive, close

Content-Length: 99

Content-type: application/x-www-form-urlencoded

Host: www.pay1pay.com

Referer: www.pay1pay.com/main/index.php

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1; .NET CLR 2.0.50727)

x-requested-with: XMLHttpRequest



cmd=GetPayCert&berbonsessionid=00017c50c2489d8eb01ef0a5b5f7fe9e&checkType=Mob&computerType=NOTEBOOK

看服务端日志是把请求结果返回了,可是客户端出现10054错误码。大神们这是怎么回事?
...全文
335 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zawgjzzl 2014-04-09
  • 打赏
  • 举报
回复
对方主机不接受数据强制关闭链接
引用
WSAECONNRESET 10054 (0x2746) An existing connection was forcibly closed by the remote host.
u010975775 2013-11-22
  • 打赏
  • 举报
回复
引用 1 楼 cchvsgame 的回复:
数据量太大,丢包了
这点数据就丢包了,不会吧
cchvsgame 2013-11-21
  • 打赏
  • 举报
回复
数据量太大,丢包了

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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