CInternetSession timeout options

  • Thread starter Thread starter Maksidrom
  • Start date Start date
M

Maksidrom

Guest
Hi all,

I have MFC C++ application. I use CHTTPFile to send POST request. Sometimes I get CInternetException "Operation timed out". I tried to increase the timeout by setting to CInternetSession object the following options to 60000 ms:

INTERNET_OPTION_CONNECT_TIMEOUT

INTERNET_OPTION_RECEIVE_TIMEOUT

INTERNET_OPTION_SEND_TIMEOUT

But that doesn't help. I tried the same request using browser. That takes less time, so set values must be enough.

I tried to check if that options work. I set 1 ms values, but no time out excpetions occured. My code is the following:

if (!m_pConn) {
if (!m_pInetSession) {
m_errorInfo = MsgNoSession;
return NULL;
}
m_pConn = m_pInetSession->GetHttpConnection(m_host, (INTERNET_PORT)m_port);
}
m_pInetSession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 1);
m_pInetSession->SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, 1);
m_pInetSession->SetOption(INTERNET_OPTION_SEND_TIMEOUT, 1);
m_pInetSession->SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, 1);
m_pInetSession->SetOption(INTERNET_OPTION_CONNECT_BACKOFF, 1);

bool done = false;
DWORD dwFlags = INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_DONT_CACHE;
if (m_bSecure) {
dwFlags |= INTERNET_FLAG_SECURE;
}
m_errorInfo = "";
pFile = m_pConn->OpenRequest(CHttpConnection::HTTP_VERB_POST, strReq, NULL, 1, NULL, NULL, dwFlags);
while (!done) {
try {
pFile->SendRequest();
DWORD dwStatusCode = 0;
pFile->QueryInfoStatusCode( dwStatusCode );
if (dwStatusCode < 400) {
pResult = ::parseXmlResult(pFile);
} else {
m_errorInfo.Format("%s %d", (LPCTSTR)MsgServerError, dwStatusCode);
}
closeConnection();
done = true;
} catch (CInternetException* e) {
if (e->m_dwError == ERROR_INTERNET_INVALID_CA ||
e->m_dwError == ERROR_INTERNET_SEC_CERT_CN_INVALID ||
e->m_dwError == ERROR_INTERNET_SEC_CERT_DATE_INVALID) {
DWORD dwRet = pFile->ErrorDlg(NULL, e->m_dwError);
if (dwRet == ERROR_INTERNET_FORCE_RETRY || dwRet == ERROR_SUCCESS) {
done = false;
} else {
done = true;
}
} else {
done = true;
}
if (done) {
char buf[BUFSIZE];
if (e->GetErrorMessage(buf, BUFSIZE)) {
m_errorInfo = MsgConnError + buf;
}
}
}
}

Does anybody knows the reason?

Thanks in advance!

Continue reading...
 
Back
Top