I am writing a visual c++ application that is supposed to send a http post message to an https endpoint (the https server's certificate is self signed). There are 2 groups of clients, 1 on windows 7 pcs and the other group on windows server 2008 rc2. After importing the server's self signed cert using the mmc console/snap-in (on both pc groups), the windows 7 pcs can make the connection without errors but on the Windows server 2008 rc2 machines, the error 12030 is always returned by winhttpsendrequest() call. Any ideas how to resolve this issue? Any help/tip will be appreciated. Thanks in advance. my code is below.
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
hSession = WinHttpOpen( userAgent,
WINHTTP_ACCESS_TYPE_NO_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0 );
if( hSession ){
hConnect = WinHttpConnect( hSession, hostname, port, 0 );
if( hConnect ){
hRequest = WinHttpOpenRequest( hConnect, L"POST", urlPath,
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_REFRESH|WINHTTP_FLAG_SECURE );
if(hRequest){
AutoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
AutoProxyOptions.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP|WINHTTP_AUTO_DETECT_TYPE_DNS_A;
AutoProxyOptions.fAutoLogonIfChallenged = TRUE;
if( WinHttpGetProxyForUrl( hSession,
fullURL,
&AutoProxyOptions,
&ProxyInfo))
{
printf("proxy info\n");
printf("access type: %ld\n",ProxyInfo.dwAccessType);
printf("list: %s\n",ProxyInfo.lpszProxy);
printf("bypass list: %s\n",ProxyInfo.lpszProxyBypass);
if( !WinHttpSetOption( hRequest,
WINHTTP_OPTION_PROXY,
&ProxyInfo,
cbProxyInfoSize ) )
{
printf("Proxy detection logic failed\n");
goto Exit;
}
}
else
{
printf("WinHttpGetProxyForUrl() returned [%d].. no proxy is used?\n", GetLastError());
}
bResults = WinHttpSendRequest(hRequest, L"Content-Type:application/x-www-form-urlencoded", 0, (LPVOID)postRequest, data_len, data_len, 0);
if ( bResults != TRUE) {
wprintf(L"WinHttpSendRequest failed (%d)\n", GetLastError());
}
else
{
//all good
bResults = WinHttpReceiveResponse( hRequest, NULL );
if( bResults )
{
do
{
dwSize = 0;
if( !WinHttpQueryDataAvailable( hRequest, &dwSize ) )
printf( "Error %u in WinHttpQueryDataAvailable.\n", GetLastError());
pszOutBuffer = new char[dwSize+1];
if( !pszOutBuffer )
{
printf( "Out of memory\n" );
dwSize=0;
}
else
{
ZeroMemory( pszOutBuffer, dwSize+1 );
if( !WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, dwSize, &dwDownloaded ) )
printf( "Error %u in WinHttpReadData.\n", GetLastError( ) );
else{
printf( "From server [");
printf( "%s", pszOutBuffer );
printf("]\n");
}
delete [] pszOutBuffer;
}
} while( dwSize > 0 );
}
}
}
else
{
wprintf(L"WinHttpOpenRequest failed (%d)\n", GetLastError());
}
}
}