CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Join Date
    Jan 2006
    Location
    Marseille, France
    Posts
    94

    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(&quot;%c&quot;), buffer[i]);
    					m_edit1 = m_edit1 + sErr;
    				}
    				else{
    					if (buffer[i] == '\n'){
    						m_edit1 = m_edit1 + &quot;\r\n&quot;;
    					}
    				}
    			}
    		
    		}
    
    	}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 :

    <!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;>
    <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=&quot;https://ssl.mywebsite.com:443/&quot;><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 ?

  2. #17
    Join Date
    Sep 2004
    Location
    Italy
    Posts
    389

    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
    Last edited by kkez; January 16th, 2007 at 09:49 AM.

  3. #18
    Join Date
    Jan 2003
    Location
    Cambridge, UK
    Posts
    752

    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
    Last edited by alex_gusev; January 16th, 2007 at 11:03 AM.
    Cheers,

    Alex
    Please rate this post if you find it helpful

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured