#include "stdafx.h"
#include <windows.h>
#include <winhttp.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#include <string.h>
#pragma comment(lib, "Winhttp.lib")
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
hSession = WinHttpOpen( L"NetIQ AppManager",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
L"cucm-11",
NULL, 0);
if (hSession)
hConnect = WinHttpConnect( hSession, L"10.71.112.251",
INTERNET_DEFAULT_HTTPS_PORT, 0);
if (hConnect)
hRequest = WinHttpOpenRequest( hConnect, L"GET", NULL,
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE);
if (hRequest)
{
unsigned long ulngSecurityOptions = 0;
unsigned long ulngSecurityOptionLen = sizeof(ulngSecurityOptions);
ulngSecurityOptions |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE |
SECURITY_FLAG_IGNORE_UNKNOWN_CA;
bResults = WinHttpSetOption(hRequest,
WINHTTP_OPTION_SECURITY_FLAGS,
&ulngSecurityOptions,
ulngSecurityOptionLen);
std::wstring strRequestHeader;
strRequestHeader = L"https://10.71.112.251//appadmin";
bResults = WinHttpSendRequest( hRequest,
strRequestHeader.c_str(),
(unsigned long)strRequestHeader.length(),
NULL,
WINHTTP_NO_REQUEST_DATA, 0,
0);
}
if (bResults)
bResults = WinHttpReceiveResponse( hRequest, NULL);
unsigned long ulngStatus = 0;
unsigned long ulngStatusSize = sizeof(ulngStatus);
if (bResults) {
bResults = WinHttpQueryHeaders(hRequest,
WINHTTP_QUERY_FLAG_NUMBER | WINHTTP_QUERY_STATUS_CODE,
0,
&ulngStatus,
&ulngStatusSize,
NULL);
}
printf( "Error Status Code - %d and last error \n", ulngStatus);
if (bResults)
{
do
{
dwSize = 0;
if (!WinHttpQueryDataAvailable( hRequest, &dwSize))
{
printf( "Error %u in WinHttpQueryDataAvailable.\n",
GetLastError());
break;
}
if (!dwSize)
break;
pszOutBuffer = new char[dwSize+1];
if (!pszOutBuffer)
{
printf("Out of memory\n");
break;
}
ZeroMemory(pszOutBuffer, dwSize+1);
if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded))
{
printf( "Error %u in WinHttpReadData.\n", GetLastError());
}
else
{
printf("%s", pszOutBuffer);
}
delete [] pszOutBuffer;
if (!dwDownloaded)
break;
} while (dwSize > 0);
}
else
{
printf( "Error %d has occurred.\n", GetLastError() );
}
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);
getchar();
return 0;
}
What I have tried:
i tried with different winhttp setoption.
it queries the default page and returns sucess(which is correct)
as per my changes it has query "https://10.71.112.251//appadmin" where reponse is sucess but opening in browser/postman gives 404 error.
Please what need to done to get response 404?