Hallo, i have serious problem with this wininet function, whe i run my program on windows 7, everything works perfectly, but when i try to us开发者_如何学编程e it on windows XP service pack 3. Sometimes it takes for HttpSendRequst too long time to finish and i really dont know why and sometimes for the same request, it finishes almost instantly. I am loading websites with my prog.
What is the difference between Win 7 and XP in wininet? I tried allmost everything but doesnt work. For example set time out for Httpsendrequest and repeat again or set maximum internet connections for more. But nothing seemed to work and the functionality was allways the same.
Please help if you can.
m_hInternet = InternetOpenA(m_strAgentName.c_str(), INTERNET_OPEN_TYPE_PRECONFIG ,
NULL, NULL, 0);
if (!m_hInternet) {
m_strLastError = "Cannot open internet";
m_lastErrorCode = GetLastError();
return false;
}
m_hSession = InternetConnectA(m_hInternet,
m_strServerName.c_str(),
m_wPort,
m_strUserName.c_str(),
m_strPassword.c_str(),
INTERNET_SERVICE_HTTP,
INTERNET_FLAG_KEEP_CONNECTION,
0);
m_hRequest = HttpOpenRequestA(m_hSession,
this->m_strMethod.c_str(),
m_strObjectName.c_str(),
NULL,
m_strReferer != "" ? m_strReferer.c_str() : NULL,
NULL,
INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_KEEP_CONNECTION,
m_ReqID);
bool result = HttpSendRequestA( m_hRequest,
this->m_strAddHeaders.size() == 0 ? NULL : this->m_strAddHeaders.c_str(),
this->m_strAddHeaders.size(),
(char*)this->m_strContent.c_str(),
this->m_strContent.size());
Do you check that request is completed successfully? There should be some response code with text. Otherwise your fast requests could be caused by abnormal termination.
If this is a complete code sample I’d suggest adding HttpEndRequest.
I have encountered this problem a couple of times when the request doesnt finish at all.
The only solution i have found to this is giving the program enough time between each request.
So you can use a buffer to store and add all the data and every X time you send it trough the request!
精彩评论