Discussion:
problems with HttpSendRequest
(too old to reply)
Jonathan Wilson
2005-01-02 13:46:25 UTC
Permalink
I have code that is calling HttpSendRequest with a https:// URL.
This call fails with 80090331 (something about not being able to find a
common algorithim)
Accessing the same https:// URL with CURL and WGET from Cygwin and Mozilla
from mozilla.org, I can get the https:// URL and see the expected contents.
Internet Explorer (which I would gather uses wininet for HTTPS) returns a
"The page cannot be displayed" error for the URL.

This is a windows XP SP2 machine with the windows firewalls and such disabled.

Is there something I can do that would help me figure out whats going on
(is there a checked/debug build of wininet.dll that would provide more
information about what is going wrong?)

I have been messing with xp-lite, xp-antispy, windows system optomizer and
group policy editor in an attempt to disable/remove stuff I dont need and I
could very well have removed or disabled something needed for wininet to be
able to correctly do https, is there any settings in these programs I could
mess with in an attempt to fix the program?
Brian Combs
2005-01-06 22:30:31 UTC
Permalink
Hello
You can check your IIS settings for SSL. Tools ->InternetOptions->Advanced
Tab. Check the different SSL and TLS settings under Security.
If they are not all checked you should check them all and then test.

You can also use debug build of WinInet to get a log.
884931 How to use the debug version of the Wininet.dll file for Internet
http://support.microsoft.com/?id=884931

Thanks
Brian [MS]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| Date: Sun, 02 Jan 2005 21:46:25 +0800
| From: Jonathan Wilson <***@tpgi.com.au>
| User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)
Gecko/20041217
| X-Accept-Language: en-au
| MIME-Version: 1.0
| Subject: problems with HttpSendRequest
| Content-Type: text/plain; charset=us-ascii; format=flowed
| Content-Transfer-Encoding: 7bit
| Message-ID: <#***@TK2MSFTNGP11.phx.gbl>
| Newsgroups:
microsoft.public.win32.programmer.networks,microsoft.public.inetsdk.programm
ing.wininet
| NNTP-Posting-Host: 220-244-120-190-wa.tpgi.com.au 220.244.120.190
| Lines: 1
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11
phx.gbl
| Xref: cpmsftngxa10.phx.gbl
microsoft.public.inetsdk.programming.wininet:11959
microsoft.public.win32.programmer.networks:21027
| X-Tomcat-NG: microsoft.public.inetsdk.programming.wininet
|
| I have code that is calling HttpSendRequest with a https:// URL.
| This call fails with 80090331 (something about not being able to find a
| common algorithim)
| Accessing the same https:// URL with CURL and WGET from Cygwin and
Mozilla
| from mozilla.org, I can get the https:// URL and see the expected
contents.
| Internet Explorer (which I would gather uses wininet for HTTPS) returns a
| "The page cannot be displayed" error for the URL.
|
| This is a windows XP SP2 machine with the windows firewalls and such
disabled.
|
| Is there something I can do that would help me figure out whats going on
| (is there a checked/debug build of wininet.dll that would provide more
| information about what is going wrong?)
|
| I have been messing with xp-lite, xp-antispy, windows system optomizer
and
| group policy editor in an attempt to disable/remove stuff I dont need and
I
| could very well have removed or disabled something needed for wininet to
be
| able to correctly do https, is there any settings in these programs I
could
| mess with in an attempt to fix the program?
|
Mahesh_p
2005-01-07 06:41:02 UTC
Permalink
I tried starting a new thread but for some reason I can't do that. So I am
just using this already exising thread to do that.

I am having a inproc activeX control from which I am trying to POST a file to
a server using HTTPS connection w/ multi-part header through ISA 2004 proxy
server. I am using HttpSendRequestEx(), InternetWriteFile() and
HttpEndRequest() to upload the file. But HttpEndRequest() always fails on
Windows 2000 IE 6.0 SP1 w/ error code 12152.

This activeX control is called from a webpage which is also accessing HTTPS
pages on the server.

Also, on Windows XP SP2, I have to set the proxy user name and password
using InternetSetOptions() or else it fails too.

The file uploaded without any problems if done directly without proxy
Has anyone got into this problem?

Here is the the psudo code which does this :
***********************************************************
int PostData()
{
bool bSuccess = FALSE;
HINTERNET hInternet = InternetOpenA(
"Post Data",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0
);

if (!hInternet )
{
return FALSE;
}

DWORD dwService = INTERNET_SERVICE_HTTP;
DWORD dwFlags = NULL;
DWORD dwContext = 0; //synchronous transfer

HINTERNET hConnection = InternetConnectA(hInternet,
m_lpszURL, (INTERNET_PORT)m_ulPort,
NULL,NULL,
dwService,dwFlags,
dwContext);

if ( !hConnection )
{
InternetCloseHandle(hInternet);
return TRUE;
}


CHAR* ppszAccept[2]={"*/*",0};

dwFlags = INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_KEEP_CONNECTION;

if (m_ulPort == INTERNET_DEFAULT_HTTPS_PORT)
dwFlags |= INTERNET_FLAG_SECURE;


HINTERNET hRequest = HttpOpenRequestA(hConnection,
"POST",
"\uploadurl",
NULL,
NULL,
(LPCSTR *)ppszAccept,
dwFlags,
NULL
);

if (!hRequest)
{
InternetCloseHandle(hConnection);
InternetCloseHandle(hInternet);
return TRUE;
}

DWORD dwSecuFlags = 0;
DWORD dwBufLen = sizeof (dwSecuFlags);
BOOL ok = InternetQueryOption (hRequest, INTERNET_OPTION_SECURITY_FLAGS,
&dwSecuFlags, &dwBufLen);
dwSecuFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA |
SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
SECURITY_FLAG_IGNORE_WRONG_USAGE;


if (!InternetSetOption (hRequest, INTERNET_OPTION_SECURITY_FLAGS,
&dwSecuFlags, sizeof(dwSecuFlags)))
{
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnection);
InternetCloseHandle(hInternet);
return TRUE;
}

CStringA strHeader;

CHAR szCookie[512];
memset(szCookie, 0, sizeof(szCookie));
sprintf(szCookie, "Cookie: %s=%s", "CYCYCY", m_lpszCookie);

CHAR szBoundary[256];
CHAR szFileHeader[512];
CHAR szFileFooter[512];

memset(szFileHeader, 0, sizeof(szFileHeader));
memset(szFileFooter, 0, sizeof(szFileFooter));

strcpy(szBoundary, "-------------12322323");

strHeader += szCookie;
strHeader += "\r\n";
strHeader += "Content-Type: multipart/form-data; boundary=";
strHeader += szBoundary;
strHeader += "\r\n";

strHeader += "Accept-Language: ";
strHeader += "en-us";
strHeader += "\r\n";
strHeader += "Results: Results=true"; //This is custom header we need

int nProxyAuthRetry = 0;

INTERNET_BUFFERSA BufferIn;

GetFileHeader(szFileHeader, szBoundary); //This generates some unique
header
GetFileFooter(szFileFooter, szBoundary); //This generates some unique
footer

bool bRetry = false;

DWORD dwBufferLength = 1024;
DWORD dwOption = INTERNET_OPTION_PROXY;
BYTE lpBuffer[1024];

//I have to do Proxy Auth. here or else it does not work even in case of
Windows XP https

if ( !m_bProxyAuthenticated && InternetQueryOption(hInternet, dwOption,
lpBuffer, &dwBufferLength) )
{
INTERNET_PROXY_INFO *pProxyInfo = (INTERNET_PROXY_INFO *)lpBuffer;
if ( pProxyInfo->dwAccessType == INTERNET_OPEN_TYPE_PROXY )
{
GetProxyAuthParams(); //This displays dialog to get user name
and password for proxy auth.
SetProxyAuthetication(hRequest); //this sets the user name and
password
}
}

again :
BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );
BufferIn.Next = NULL;
BufferIn.lpcszHeader = strHeader;
BufferIn.dwHeadersLength = strHeader.GetLength();
BufferIn.dwHeadersTotal = strHeader.GetLength();
BufferIn.lpvBuffer = NULL;
BufferIn.dwBufferLength = 0;
BufferIn.dwBufferTotal = ( szErrorInfo ? strlen(szFileHeader) +
strlen(szFileFooter) : m_ulTotalDataSize + strlen(szFileHeader) +
strlen(szFileFooter));
BufferIn.dwOffsetLow = 0;
BufferIn.dwOffsetHigh = 0;

if(!HttpSendRequestExA( hRequest, &BufferIn, NULL, HSR_INITIATE |
HSR_SYNC, 0))
{
if ( IsProxyAuthRequired(hRequest) ) //this will check if the error
was because we still need to set the password
{
GetProxyAuthParams();
SetProxyAuthetication(hRequest);
goto again;
}

InternetCloseHandle(hRequest);
InternetCloseHandle(hConnection);
InternetCloseHandle(hInternet);
return FALSE;
}

ULONG ulBytesToWrite;
ULONG ulTotalBytesWritten = 0;
ULONG ulBytesWritten = 0;

bSuccess = TRUE;

if ( szErrorInfo == NULL )
{
//First send the Boundary prefix required for the file
if (!InternetWriteFile( hRequest, szFileHeader,
(DWORD)strlen(szFileHeader), &ulBytesWritten) )
{
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnection);
InternetCloseHandle(hInternet);
return FALSE;
}

//Now send the actual file

ulBytesToWrite = m_ulTotalDataSize;

ULONG ulIndex = 0;
while (ulIndex < m_ulTotalDataSize )
{
if (!InternetWriteFile( hRequest, &(m_lpDataBuffer[ulIndex]),
ulBytesToWrite, &ulBytesWritten) )
{
bSuccess = FALSE;
break;
}
ulIndex += ulBytesWritten;
ulBytesToWrite = ( m_ulTotalDataSize - ulIndex );
}

if( !bSuccess )
{
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnection);
InternetCloseHandle(hInternet);
return FALSE;
}
}

//Now send the end Boundary prefix required for the file
if ( !InternetWriteFile( hRequest, szFileFooter, strlen(szFileFooter),
&ulBytesWritten) )
{
//Log GetLastError()
}

if( !HttpEndRequestA(hRequest, NULL, 0, 0) )
{
//Log GetLastError()
bSuccess = FALSE;
}
else
{
bSuccess = TRUE;
}

//Read and discard any data sent by the server

InternetCloseHandle(hRequest);
InternetCloseHandle(hConnection);
InternetCloseHandle(hInternet);
return bSuccess;
}

***********************************************************
Brian Combs
2005-01-07 16:14:39 UTC
Permalink
Hello
The error you are getting is 12152 ERROR_HTTP_INVALID_SERVER_RESPONSE
The server response could not be parsed.

You should get a network trace and WinINet log to see what return data is
causing this error.
884931 How to use the debug version of the Wininet.dll file for Internet
http://support.microsoft.com/?id=884931

Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| Thread-Topic: problems with HttpSendRequest
| thread-index: AcT0g9q1dqAWpcSOTCSmpE23TbRkwQ==
| X-WBNR-Posting-Host: 24.6.43.144
| From: "=?Utf-8?B?TWFoZXNoX3A=?=" <***@yahoo.com>
| References: <#***@TK2MSFTNGP11.phx.gbl>
<***@cpmsftngxa10.phx.gbl>
| Subject: RE: problems with HttpSendRequest
| Date: Thu, 6 Jan 2005 22:41:02 -0800
| Lines: 263
| Message-ID: <7EC7503F-3BBD-4762-A174-***@microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.inetsdk.programming.wininet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl
microsoft.public.inetsdk.programming.wininet:11971
| X-Tomcat-NG: microsoft.public.inetsdk.programming.wininet
|
| I tried starting a new thread but for some reason I can't do that. So I
am
| just using this already exising thread to do that.
|
| I am having a inproc activeX control from which I am trying to POST a
file to
| a server using HTTPS connection w/ multi-part header through ISA 2004
proxy
| server. I am using HttpSendRequestEx(), InternetWriteFile() and
| HttpEndRequest() to upload the file. But HttpEndRequest() always fails on
| Windows 2000 IE 6.0 SP1 w/ error code 12152.
|
| This activeX control is called from a webpage which is also accessing
HTTPS
| pages on the server.
|
| Also, on Windows XP SP2, I have to set the proxy user name and password
| using InternetSetOptions() or else it fails too.
|
| The file uploaded without any problems if done directly without proxy
| Has anyone got into this problem?
|
| Here is the the psudo code which does this :
| ***********************************************************
| int PostData()
| {
| bool bSuccess = FALSE;
| HINTERNET hInternet = InternetOpenA(
| "Post Data",
| INTERNET_OPEN_TYPE_PRECONFIG,
| NULL,
| NULL,
| 0
| );
|
| if (!hInternet )
| {
| return FALSE;
| }
|
| DWORD dwService = INTERNET_SERVICE_HTTP;
| DWORD dwFlags = NULL;
| DWORD dwContext = 0; //synchronous transfer
|
| HINTERNET hConnection = InternetConnectA(hInternet,
| m_lpszURL, (INTERNET_PORT)m_ulPort,
| NULL,NULL,
| dwService,dwFlags,
| dwContext);
|
| if ( !hConnection )
| {
| InternetCloseHandle(hInternet);
| return TRUE;
| }
|
|
| CHAR* ppszAccept[2]={"*/*",0};
|
| dwFlags = INTERNET_FLAG_RELOAD |
| INTERNET_FLAG_NO_CACHE_WRITE |
| INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
| INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
| INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
| INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
| INTERNET_FLAG_KEEP_CONNECTION;
|
| if (m_ulPort == INTERNET_DEFAULT_HTTPS_PORT)
| dwFlags |= INTERNET_FLAG_SECURE;
|
|
| HINTERNET hRequest = HttpOpenRequestA(hConnection,
| "POST",
| "\uploadurl",
| NULL,
| NULL,
| (LPCSTR *)ppszAccept,
| dwFlags,
| NULL
| );
|
| if (!hRequest)
| {
| InternetCloseHandle(hConnection);
| InternetCloseHandle(hInternet);
| return TRUE;
| }
|
| DWORD dwSecuFlags = 0;
| DWORD dwBufLen = sizeof (dwSecuFlags);
| BOOL ok = InternetQueryOption (hRequest,
INTERNET_OPTION_SECURITY_FLAGS,
| &dwSecuFlags, &dwBufLen);
| dwSecuFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA |
| SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
| SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
| SECURITY_FLAG_IGNORE_WRONG_USAGE;
|
|
| if (!InternetSetOption (hRequest, INTERNET_OPTION_SECURITY_FLAGS,
| &dwSecuFlags, sizeof(dwSecuFlags)))
| {
| InternetCloseHandle(hRequest);
| InternetCloseHandle(hConnection);
| InternetCloseHandle(hInternet);
| return TRUE;
| }
|
| CStringA strHeader;
|
| CHAR szCookie[512];
| memset(szCookie, 0, sizeof(szCookie));
| sprintf(szCookie, "Cookie: %s=%s", "CYCYCY", m_lpszCookie);
|
| CHAR szBoundary[256];
| CHAR szFileHeader[512];
| CHAR szFileFooter[512];
|
| memset(szFileHeader, 0, sizeof(szFileHeader));
| memset(szFileFooter, 0, sizeof(szFileFooter));
|
| strcpy(szBoundary, "-------------12322323");
|
| strHeader += szCookie;
| strHeader += "\r\n";
| strHeader += "Content-Type: multipart/form-data; boundary=";
| strHeader += szBoundary;
| strHeader += "\r\n";
|
| strHeader += "Accept-Language: ";
| strHeader += "en-us";
| strHeader += "\r\n";
| strHeader += "Results: Results=true"; //This is custom header we need
|
| int nProxyAuthRetry = 0;
|
| INTERNET_BUFFERSA BufferIn;
|
| GetFileHeader(szFileHeader, szBoundary); //This generates some unique
| header
| GetFileFooter(szFileFooter, szBoundary); //This generates some unique
| footer
|
| bool bRetry = false;
|
| DWORD dwBufferLength = 1024;
| DWORD dwOption = INTERNET_OPTION_PROXY;
| BYTE lpBuffer[1024];
|
| //I have to do Proxy Auth. here or else it does not work even in case of
| Windows XP https
|
| if ( !m_bProxyAuthenticated && InternetQueryOption(hInternet,
dwOption,
| lpBuffer, &dwBufferLength) )
| {
| INTERNET_PROXY_INFO *pProxyInfo = (INTERNET_PROXY_INFO
*)lpBuffer;
| if ( pProxyInfo->dwAccessType == INTERNET_OPEN_TYPE_PROXY )
| {
| GetProxyAuthParams(); //This displays dialog to get user name
| and password for proxy auth.
| SetProxyAuthetication(hRequest); //this sets the user name
and
| password
| }
| }
|
| again :
| BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );
| BufferIn.Next = NULL;
| BufferIn.lpcszHeader = strHeader;
| BufferIn.dwHeadersLength = strHeader.GetLength();
| BufferIn.dwHeadersTotal = strHeader.GetLength();
| BufferIn.lpvBuffer = NULL;
| BufferIn.dwBufferLength = 0;
| BufferIn.dwBufferTotal = ( szErrorInfo ? strlen(szFileHeader) +
| strlen(szFileFooter) : m_ulTotalDataSize + strlen(szFileHeader) +
| strlen(szFileFooter));
| BufferIn.dwOffsetLow = 0;
| BufferIn.dwOffsetHigh = 0;
|
| if(!HttpSendRequestExA( hRequest, &BufferIn, NULL, HSR_INITIATE |
| HSR_SYNC, 0))
| {
| if ( IsProxyAuthRequired(hRequest) ) //this will check if the
error
| was because we still need to set the password
| {
| GetProxyAuthParams();
| SetProxyAuthetication(hRequest);
| goto again;
| }
|
| InternetCloseHandle(hRequest);
| InternetCloseHandle(hConnection);
| InternetCloseHandle(hInternet);
| return FALSE;
| }
|
| ULONG ulBytesToWrite;
| ULONG ulTotalBytesWritten = 0;
| ULONG ulBytesWritten = 0;
|
| bSuccess = TRUE;
|
| if ( szErrorInfo == NULL )
| {
| //First send the Boundary prefix required for the file
| if (!InternetWriteFile( hRequest, szFileHeader,
| (DWORD)strlen(szFileHeader), &ulBytesWritten) )
| {
| InternetCloseHandle(hRequest);
| InternetCloseHandle(hConnection);
| InternetCloseHandle(hInternet);
| return FALSE;
| }
|
| //Now send the actual file
|
| ulBytesToWrite = m_ulTotalDataSize;
|
| ULONG ulIndex = 0;
| while (ulIndex < m_ulTotalDataSize )
| {
| if (!InternetWriteFile( hRequest, &(m_lpDataBuffer[ulIndex]),
| ulBytesToWrite, &ulBytesWritten) )
| {
| bSuccess = FALSE;
| break;
| }
| ulIndex += ulBytesWritten;
| ulBytesToWrite = ( m_ulTotalDataSize - ulIndex );
| }
|
| if( !bSuccess )
| {
| InternetCloseHandle(hRequest);
| InternetCloseHandle(hConnection);
| InternetCloseHandle(hInternet);
| return FALSE;
| }
| }
|
| //Now send the end Boundary prefix required for the file
| if ( !InternetWriteFile( hRequest, szFileFooter,
strlen(szFileFooter),
| &ulBytesWritten) )
| {
| //Log GetLastError()
| }
|
| if( !HttpEndRequestA(hRequest, NULL, 0, 0) )
| {
| //Log GetLastError()
| bSuccess = FALSE;
| }
| else
| {
| bSuccess = TRUE;
| }
|
| //Read and discard any data sent by the server
|
| InternetCloseHandle(hRequest);
| InternetCloseHandle(hConnection);
| InternetCloseHandle(hInternet);
| return bSuccess;
| }
|
| ***********************************************************
|
|
|
Mahesh_p
2005-01-07 22:43:02 UTC
Permalink
Hi Brian,

Thanks for your reply.

What I found was, for proxy, by default WinInet uses HTTP 1.0 no matter what
I send in HttpOpenRequest() call, which was causing WinInet to fail in POST
on Windows 2000 system. But if I turn on Http 1.1 for proxy in IE settings
everything works fine.

But now my problem is even if I programmatically set the value in the
registry (HKCU\SW\Msft...ProxyHttp1.1) to use HTTP 1.1 for proxy, my winInet
calls in the activex control still sends data using Http 1.0 as I am running
in IE which was started w/ HTTP 1.0.

So is there a way to forcefully let WinInet use 1.1 instead of 1.0 ?

Thanks,
Mahesh

Continue reading on narkive:
Loading...