-
October 18th, 2006, 05:13 AM
#1
WinInet : Error 12031
Hi,
My code was running correctly for a long, and now, only on my pc, I got an error code while getting a ssl web page,
here is the error :
ERROR_INTERNET_CONNECTION_RESET
12031
The connection with the server has been reset
here a piece of my code :
Code:
hInternetSession = InternetOpen (USER_AGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL) ;
if (hInternetSession)
{
hHttpSession = InternetOpenUrl( hInternetSession, "HTTPS://SSL.MON_URL.COM", NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_UI | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD| INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID, 0 ) ;
if (hHttpSession){
InternetCloseHandle( hHttpSession );
}
else{
_cprintf("Err : %d\n", GetLastError());
}
InternetCloseHandle (hInternetSession) ;
}
I read many page found on google for this error, but I didn't found how to fix this problem,
could you help me please ?
jb
[edit] : Replacing "INTERNET_OPEN_TYPE_PRECONFIG" by "INTERNET_OPEN_TYPE_DIRECT" or "INTERNET_OPEN_TYPE_PROXY" doesn't fix anything
Last edited by FireJocker; October 18th, 2006 at 05:17 AM.
-
October 18th, 2006, 07:17 AM
#2
Re: WinInet : Error 12031
Try to call InternetGetLastResponseInfo, it may output something helpful.
EDIT: ERROR_INTERNET_CONNECTION_RESET should mean that the connection was lost. Were you downloading something in the meantime? Do you get this error every time? If you connect with the browser do you have any problem?
Last edited by kkez; October 18th, 2006 at 07:24 AM.
-
October 18th, 2006, 07:55 AM
#3
Re: WinInet : Error 12031
Now, it re-run correctly :S
So, i can't get any error to analyse it ?
While it didn't ran, internet was ok, i successfully surf on web
so what's wrong ?
-
October 18th, 2006, 08:26 AM
#4
Re: WinInet : Error 12031
-
October 18th, 2006, 08:30 AM
#5
Re: WinInet : Error 12031
-
January 11th, 2007, 05:19 AM
#6
Re: WinInet : Error 12031
The problem seem being due to AtiveSync,
anyone knows something about it ?
-
January 11th, 2007, 06:00 AM
#7
Re: WinInet : Error 12031
are you running it on PC or mobile device? because ActiveSync is in a game only if you are on PDA
besides, InternetOpenUrl just fails sometimes for unknown reason, InternetOpen is more reliable
Cheers,
Alex
Please rate this post if you find it helpful
-
January 11th, 2007, 08:59 AM
#8
Re: WinInet : Error 12031
I work on a PDA using WinCE 5.0
but, even disconnected from PC, the embedded application continue to get error 12031 on InternetOpenURL
-
January 11th, 2007, 09:10 AM
#9
Re: WinInet : Error 12031
Writing InternetOpen is more reliable , you seems telling InternetOpen might be used instead of InternetOpenUrl.
But I also use it,
here is my code (for eMbedded Visual C++)
Code:
CStatic * txt = (CStatic *) GetDlgItem(IDC_STATIC1),
* txtErrCode = (CStatic *) GetDlgItem(IDC_STATIC_ERRCODE);
CString sErr;
DWORD flags;
HINTERNET hInternetSession, hHttpSession;
flags = INTERNET_CONNECTION_OFFLINE;
BOOL connected = InternetGetConnectedState(&flags, 0);
if (connected)
{
connected = FALSE;
hInternetSession = InternetOpen (USER_AGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL) ;
if (hInternetSession)
{
hHttpSession = InternetOpenUrl( hInternetSession, _T("http://www.google.com"), NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_UI | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD| INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID, 0 ) ;
connected = hHttpSession != NULL;
if (connected)
InternetCloseHandle( hHttpSession );
else
txt->SetWindowText(_T("Step 3 HS"));
InternetCloseHandle (hInternetSession) ;
}
else
txt->SetWindowText(_T("Step 2 HS"));
}
else
txt->SetWindowText(_T("Step 1 HS"));
sErr.Format(_T("%d"), GetLastError());
txtErrCode->SetWindowText(sErr);
Is it good ? or how modify it ?
-
January 11th, 2007, 09:35 AM
#10
Re: WinInet : Error 12031
sorry, I've meant InternetConnect
something like the following (blame me, that is just my old test code for WinCE )
Code:
void CWceHttpDlg::OnButton2()
{
UpdateData();
CString sInfo;
DWORD dwConnStateFlags = 0;
BOOL bRes = InternetGetConnectedState(&dwConnStateFlags,0);
if ( bRes )
{
sInfo.Format(L"ConnState = %X",dwConnStateFlags);
AfxMessageBox(sInfo);
}
HINTERNET hGETRequest;
DWORD dwFlags = INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID|INTERNET_FLAG_IGNORE_CERT_DATE_INVALID|
INTERNET_FLAG_PRAGMA_NOCACHE;
LPTSTR pszAcceptTypes [] = {TEXT("text/*"), NULL};
TCHAR szServer [1024];
TCHAR szEndpoint [1024];
URL_COMPONENTS crackedURL;
int nPort;
HINTERNET hConnect;
HINTERNET hOpen;
CString sHTTPHeader;
if (m_sURL.IsEmpty ())
return;
//Crack URL ...
ZeroMemory (& crackedURL, sizeof (URL_COMPONENTS));
crackedURL.dwStructSize = sizeof (URL_COMPONENTS);
crackedURL.lpszHostName = szServer;
crackedURL.dwHostNameLength = 1024;
crackedURL.lpszUrlPath = szEndpoint;
crackedURL.dwUrlPathLength = 1024;
InternetCrackUrl (m_sURL, 0, 0, &crackedURL);
nPort = crackedURL.nPort;
hOpen = InternetOpen (L"WceHttp", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if ( !hOpen )
{
AfxMessageBox(L"Failed to open WinInet");
return;
}
hConnect = InternetConnect (hOpen, szServer, nPort, L"", L"", INTERNET_SERVICE_HTTP, 0, 0);
if ( !hConnect )
{
sInfo.Format(L"InternetConnect failed: %lu", GetLastError ());
AfxMessageBox(sInfo);
return;
}
// Open an HTTP request handle...
hGETRequest = HttpOpenRequest (hConnect, L"GET", szEndpoint, NULL, NULL, (LPCTSTR*) pszAcceptTypes, dwFlags, 0);
if ( !hGETRequest )
{
sInfo.Format(L"HttpOpenRequest failed: %lu", GetLastError ());
AfxMessageBox(sInfo);
InternetCloseHandle (hConnect);
return;
}
// send the request...
sHTTPHeader = L"Content-Type: text/*\r\n";
if (! HttpSendRequest (hGETRequest, (LPCTSTR) sHTTPHeader, sHTTPHeader.GetLength (), NULL, 0))
{
sInfo.Format(L"HttpSendRequest failed: %lu", GetLastError ());
AfxMessageBox(sInfo);
InternetCloseHandle (hGETRequest);
InternetCloseHandle (hConnect);
return;
}
DWORD dwNumberOfBytesAvailable = 0;
if ( InternetQueryDataAvailable(hGETRequest,&dwNumberOfBytesAvailable,0,0) )
{
sInfo.Format(L"File size is : %lu",dwNumberOfBytesAvailable);
AfxMessageBox(sInfo);
}
char szBuffer[4096];
DWORD dwNumberOfBytesRead = 0;
TCHAR wszTmp[4097];
int i = 0;
DWORD dwTotal = 0;
while ( InternetReadFile(hGETRequest, szBuffer, 4096,&dwNumberOfBytesRead) && dwNumberOfBytesRead )
{
memset(wszTmp,0,sizeof(wszTmp));
MultiByteToWideChar(CP_ACP,0,szBuffer,dwNumberOfBytesRead,wszTmp,sizeof(wszTmp));
i++;
dwTotal += dwNumberOfBytesRead;
}
sInfo.Format(L"Read %d block(s) - %lu byte(s)",i,dwTotal);
AfxMessageBox(sInfo);
InternetCloseHandle (hGETRequest);
InternetCloseHandle (hConnect);
InternetCloseHandle (hOpen);
}
Cheers,
Alex
Please rate this post if you find it helpful
-
January 11th, 2007, 10:03 AM
#11
Re: WinInet : Error 12031
Thanks for your help,
I'll follow your code.
-
January 11th, 2007, 10:17 AM
#12
Re: WinInet : Error 12031
Argh !
I won't see I need to write the protocole by myself.
It's an SSL connexion, it's not so easy like "GET /"
-
January 11th, 2007, 10:20 AM
#13
Re: WinInet : Error 12031
well, it is almost the same, you get it from InternetCrackUrl() and specify appropriate in InternetConnect()
Cheers,
Alex
Please rate this post if you find it helpful
-
January 11th, 2007, 10:23 AM
#14
Re: WinInet : Error 12031
I never write SSL request, do you know where i can found any information about this ?
"SSL request" on google is loosing me !
thanks.
-
January 11th, 2007, 10:50 AM
#15
Re: WinInet : Error 12031
why should you deal with it? WinInet does it already, so just specify correct flags (for HTTPS)
I've successfully communicated with such code to Web Service over https/SSL connections
Cheers,
Alex
Please rate this post if you find it helpful
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|