Hallo,
ich habe versucht eine Lösung per Winhttp zu finden, aber leider funktioniert das SSL dort nicht, weil es nicht Kompeliert.
Ich habe auch schon google dazu befragt, konnte aber bisher nichts finden…
#include
#include
#include
#include
#include
#pragma comment(lib, "winhttp.lib")
void main(){
char y;
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"WinHTTP Example/1.0",
WINHTTP\_ACCESS\_TYPE\_DEFAULT\_PROXY,
WINHTTP\_NO\_PROXY\_NAME,
WINHTTP\_NO\_PROXY\_BYPASS, 0);
// Specify an HTTP server.
if (hSession)
hConnect = WinHttpConnect( hSession, L"https://google.de",
INTERNET\_DEFAULT\_HTTPS\_PORT, 0);
// Create an HTTP request handle.
if (hConnect)
hRequest = WinHttpOpenRequest( hConnect, L"GET", NULL,
NULL, WINHTTP\_NO\_REFERER,
WINHTTP\_DEFAULT\_ACCEPT\_TYPES,
WINHTTP\_FLAG\_SECURE);
// Send a request.
if (hRequest)
bResults = WinHttpSendRequest( hRequest,
WINHTTP\_NO\_ADDITIONAL\_HEADERS,
0, WINHTTP\_NO\_REQUEST\_DATA, 0,
0, 0);
if( !WinHttpReceiveResponse( hRequest, NULL ) )
{
if( GetLastError( ) == ERROR\_WINHTTP\_CLIENT\_AUTH\_CERT\_NEEDED )
{
//MY is the store the certificate is in.
hMyStore = CertOpenSystemStore( 0, TEXT("MY") );
if( hMyStore )
{
pCertContext = CertFindCertificateInStore( hMyStore,
X509\_ASN\_ENCODING | PKCS\_7\_ASN\_ENCODING,
0,
CERT\_FIND\_SUBJECT\_STR,
(LPVOID) szCertName, //Subject string in the certificate.
NULL );
if( pCertContext )
{
WinHttpSetOption( hRequest,
WINHTTP\_OPTION\_CLIENT\_CERT\_CONTEXT,
(LPVOID) pCertContext,
sizeof(CERT\_CONTEXT) );
CertFreeCertificateContext( pCertContext );
}
CertCloseStore( hMyStore, 0 );
// NOTE: Application should now resend the request.
}
}
}
// End the request.
if (bResults)
bResults = WinHttpReceiveResponse( hRequest, NULL);
// Keep checking for data until there is nothing left.
if (bResults)
do
{
// Check for available data.
dwSize = 0;
if (!WinHttpQueryDataAvailable( hRequest, &dwSize))
printf("Error %u in WinHttpQueryDataAvailable.\n", GetLastError());
// Allocate space for the buffer.
pszOutBuffer = new char[dwSize+1];
if (!pszOutBuffer)
{
printf("Out of memory\n");
dwSize=0;
}
else
{
// Read the Data.
ZeroMemory(pszOutBuffer, dwSize+1);
if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded))
printf( "Error %u in WinHttpReadData.\n", GetLastError());
else
printf( "%s\n", pszOutBuffer);
// Free the memory allocated to the buffer.
delete [] pszOutBuffer;
}
} while (dwSize \> 0);
// Report any errors.
if (!bResults)
printf("Error %d has occurred.\n", GetLastError());
// Close any open handles.
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);
std::cin \>\> y;
Der mommentane Code.
Gruß
S.