zswzwy 2016年01月20日
InternetOpen循环调用400多次以后,速度明显变慢,是什么原因?
这时候用浏览器打开网页也很慢,怎么解决?求高人解答!

代码类似这样,用LIBCURL也不行。
HINTERNET hInternet = InternetOpen(_T("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"),  
INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (NULL == hInternet)
{
return _T("");
}

LONG nPort = 80;
HINTERNET hSession = InternetConnect(hInternet, _T("www.baidu.com"),
(INTERNET_PORT)nPort, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if(hSession == NULL)
{
return _T("");
}

CString sHtmlHeader;
sHtmlHeader = _T("Content-Type: application/x-www-form-urlencoded\r\n");
sHtmlHeader += _T("Accept: */*\r\n");
sHtmlHeader += _T("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0\r\n");
sHtmlHeader += _T("Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3\r\n");
sHtmlHeader += _T("Host: www.baidu.com\r\n");
sHtmlHeader += _T("Referer: ")+strURL;

HINTERNET hRequest = HttpOpenRequest(hSession, _T("GET"), strGetURL,
_T("HTTP/1.1"), _T(""), 0, INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_NO_CACHE_WRITE, 0);

int iTimeout = 10000;
InternetSetOption(hRequest, INTERNET_OPTION_CONNECT_TIMEOUT,
&iTimeout, sizeof(iTimeout));
InternetSetOption(hRequest, INTERNET_OPTION_SEND_TIMEOUT,
&iTimeout, sizeof(iTimeout));
InternetSetOption(hRequest, INTERNET_OPTION_RECEIVE_TIMEOUT,
&iTimeout, sizeof(iTimeout));
InternetSetOption(hRequest, INTERNET_OPTION_DATA_SEND_TIMEOUT,
&iTimeout, sizeof(iTimeout));
InternetSetOption(hRequest, INTERNET_OPTION_DATA_RECEIVE_TIMEOUT,
&iTimeout, sizeof(iTimeout));
InternetSetOption(hRequest, INTERNET_OPTION_LISTEN_TIMEOUT,
&iTimeout, sizeof(iTimeout));

BOOL bResult = HttpSendRequest(hRequest, sHtmlHeader.GetBuffer(),
sHtmlHeader.GetLength(), _T(""), 0);
...全文
1458 点赞 收藏 11
写回复
11 条回复

还没有回复,快来抢沙发~

发动态
发帖子
网络编程
创建于2007-09-28

7878

社区成员

6.4w+

社区内容

VC/MFC 网络编程
社区公告
暂无公告