Re: WinInet : Error 12031
Hi,
I'm trying many things to get it, but I failed,
here is my test code :
Code:
CString sErr;
m_edit1 = "";
// Open Internet session.
HINTERNET hSession = ::InternetOpen (USER_AGENT, PRE_CONFIG_INTERNET_ACCESS, NULL, NULL, NULL) ;
// Connect to www.microsoft.com.
HINTERNET hConnect = ::InternetConnect(hSession, _T("ssl.mywebsite.com"), 443, _T(""), _T(""), INTERNET_SERVICE_HTTP, 0,0) ;
// Request the file /MSDN/MSDNINFO/ from the server.
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
_T("GET"),
_T("/index.php4?p=10&login=jb&password=test"),
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0) ;
// Send the request.
BOOL bSendRequest = ::HttpSendRequest(hHttpFile, NULL, 0, 0, 0);
DWORD dwFileSize = 4096;
char buffer[4096+1];
m_edit1 = "";
DWORD dwBytesRead ;
BOOL bRead;
int i, nRead = 0;
do
{
nRead++;
bRead = ::InternetReadFile( hHttpFile,
buffer,
dwFileSize+1,
&dwBytesRead);
if ( (bRead) && (dwBytesRead>0) ){
for(i=0; i<dwBytesRead; i++){
if ( (buffer[i] != '\n') && (buffer[i] != '\r') ){
sErr.Format(_T("%c"), buffer[i]);
m_edit1 = m_edit1 + sErr;
}
else{
if (buffer[i] == '\n'){
m_edit1 = m_edit1 + "\r\n";
}
}
}
}
}while( (bRead == TRUE) && (dwBytesRead > 0) && (nRead < 10) );
// Close all of the Internet handles.
::InternetCloseHandle(hHttpFile);
::InternetCloseHandle(hConnect) ;
::InternetCloseHandle(hSession) ;
// Display the file in an edit control.
UpdateData(FALSE);
And I got :
Quote:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.<P>
Reason: You're speaking plain HTTP to an SSL-enabled server port.<BR>
Instead use the HTTPS scheme to access this URL, please.<BR>
<BLOCKQUOTE>Hint: <A HREF="https://ssl.mywebsite.com:443/"><B>https://ssl.mywebsite.com:443/</B></A></BLOCKQUOTE><P>
<HR>
<ADDRESS>Apache/1.3.37 Server at ssl.mywebsite.com Port 443</ADDRESS>
</BODY></HTML>
Any Idea ?
Re: WinInet : Error 12031
Try to use the flag INTERNET_FLAG_SECURE with the flags used in the call to HttpOpenRequest:
Code:
HttpOpenRequest(hConnect, ... INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_SECURE, 0);
EDIT: btw, here's a kb from microsoft on this subject: http://support.microsoft.com/kb/168151
Re: WinInet : Error 12031
here is another sample:
http://www.codeproject.com/internet/...&select=953306
and yes, you have to specify INTERNET_FLAG_SECURE in HttpOpenRequest