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?
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 ?
Re: WinInet : Error 12031
Re: WinInet : Error 12031
Re: WinInet : Error 12031
The problem seem being due to AtiveSync,
anyone knows something about it ?
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
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
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 ?
Re: WinInet : Error 12031
sorry, I've meant InternetConnect :blush:
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);
}
Re: WinInet : Error 12031
Thanks for your help,
I'll follow your code.
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 /"
Re: WinInet : Error 12031
well, it is almost the same, you get it from InternetCrackUrl() and specify appropriate in InternetConnect()
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.
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