问题描述
- 关于MFC中SendRequest操作超时的函数
-
这个是我用HttpWatch抓到的的包,那个圈起来的字符粘到vc6中就成?了,怎么办?#include "AFXINET.H" INT CLOGIN::GetFile(const CString strUrl)//,const CString strSavePath) { // AfxMessageBox(strUrl); unsigned short nPort; //用于保存目标HTTP服务端口 CString strServer, strObject;//strServer用于保存服务器地址,strObject用于保存文件对象名称 DWORD dwServiceType,dwRet; //dwServiceType用于保存服务类型,dwRet用于保存提交GET请求返回的状态号 //解析URL,获取信息 if(!AfxParseURL(strUrl, dwServiceType, strServer, strObject, nPort)) { //解析失败,该Url不正确 return -1; } //创建网络连接对象,HTTP连接对象指针和用于该连接的HttpFile文件对象指针,注意delete CInternetSession intsess; CHttpFile *pHtFile = NULL; //建立网络连接 CHttpConnection *pHtCon = intsess.GetHttpConnection(strServer,nPort);//_T("120620223"),_T("1a993111a5")); if(pHtCon == NULL) { //建立网络连接失败 intsess.Close(); return -2; } CString FormDataType = _T("Content-Type:application/x-www-form-urlencoded"); //CString m_formdat = _T("action=login&login_username=120620223&login_password=1a993111a5"); CString m_formdat = _T("RadioButtonList1=???&TextBox2=1a993111a &txtUserName=120620223"); //发起GET请求 pHtFile = pHtCon->OpenRequest(CHttpConnection::HTTP_VERB_GET,strObject); if(pHtFile == NULL) { //发起GET请求失败 intsess.Close(); delete pHtCon; pHtCon = NULL; return -3; } //提交请求头信息 pHtFile->AddRequestHeaders(_T("POST /(gac14yvwcsjrzj45cx1fq4ed)/default2.aspx HTTP/1.1")); pHtFile->AddRequestHeaders(_T("Accept:text/html, application/xhtml+xml, */*")); pHtFile->AddRequestHeaders(_T("Accept-Encoding:gzip, deflate")); pHtFile->AddRequestHeaders(_T("Accept-Language:zh-CN")); pHtFile->AddRequestHeaders(_T("Cache-Control:no-cache")); pHtFile->AddRequestHeaders(_T("Connection:Keep-Alive")); pHtFile->AddRequestHeaders(_T("Content-Length:192")); pHtFile->AddRequestHeaders(_T("Content-Type:application/x-www-form-urlencoded")); pHtFile->AddRequestHeaders(_T("Cookie:safedog-flow-item=40A0DA8385864A8908D8E58047659734;")); pHtFile->AddRequestHeaders(_T("DNT:1")); pHtFile->AddRequestHeaders(_T("Host:202.200.144.63")); pHtFile->AddRequestHeaders(_T("Referer:http://202.200.144.63/(gac14yvwcsjrzj45cx1fq4ed)/default2.aspx")); pHtFile->AddRequestHeaders(_T("User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")); pHtFile->AddRequestHeaders(_T("ASP.NET_SessionId=hdlg1oi5wz1ibd3ot3omqhr3")); pHtFile->AddRequestHeaders(_T("X-HttpWatch-RID 74624-10032")); pHtFile->SendRequest(FormDataType,FormDataType.GetLength(),(LPVOID)(LPCTSTR)m_formdat,m_formdat.GetLength()); //获取服务器返回的状态号 pHtFile->QueryInfoStatusCode(dwRet); if (dwRet != HTTP_STATUS_OK) { //服务器不接受请求 intsess.Close(); delete pHtCon; pHtCon = NULL; delete pHtFile; pHtFile = NULL; return -4; }
解决方案
解决方案二:
数据可能不是字符串,编码格式。
网络超时,先检查网络连接,服务器访问等
解决方案三:
我调试运行了几次,异常都是从下边这句抛出的,然后就出现提示框“操作超时”
pHtFile->SendRequest(FormDataType,FormDataType.GetLength(),(LPVOID)(LPCTSTR)m_formdat,m_formdat.GetLength());
时间: 2024-10-06 20:20:53