I am attempting to connect to a proxy using WinHTTP. However, the output says "Error 122 in WinHttpQueryOption." I'm not sure why this is. "proxy" is just an std::string like "21.169.73.65:34679". The problematic code is below.
std::wstring stemp = std::wstring(proxy.begin(), proxy.end());
const wchar_t* sw = stemp.c_str();
HINTERNET hSession2=WinHttpOpen(L"WinHTTP Example/1.0", WINHTTP_ACCESS_TYPE_NAMED_PROXY, L"http://"+*sw, WINHTTP_NO_PROXY_BYPASS, 0);
if (hSession2)
{
// Use WinHttpQueryOption to retrieve internet options.
if (WinHttpQueryOption( hSession2,
WINHTTP_OPTION_CONNECT_TIMEOUT,
&data, &dwSize))
{
printf("Connection timeout: %u ms\n\n",data);
}
else
{
printf( "Error %u in WinHttpQueryOption.\n",
GetLastError());
}
// When finished, release the HINTERNET handle.
WinHttpCloseHandle(hSession2);
}
else
{
printf("Error %u in WinHttpOpen.\n", GetLastError());
}
I read some other posts that had to do with this error, but they were not specifically about WinHTTP so I was not sure what should be done about it.