I am running a Python server with HTTPS enabled, using cert.pem and key.pem generated by me. I would like to send a GET
request to an endpoint on that server.
When I disable HTTPS, everything works fine. But when enabled, the program simply does not show anything.
According to the accepted answer for this question, I should use INTERNET_FLAG_SECURE
, but this seems to break the function in a way that does not show any errors.
std::string GET(std::string data ,std::string endpoint )
{
std::string result;
static TCHAR hdrs[] = _T("Content-Type: application/json");
static LPCSTR accept[2]={"*/*", NULL};
// for clarity, error-checking has been removed
HINTERNET hSession = InternetOpen(DEFAULT_USERAGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hSession, MY_HOST, ALT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest = HttpOpenRequest(hConnect, "GET", endpoint.c_str(), NULL, NULL, accept, INTERNET_FLAG_SECURE, 1);
if(HttpSendRequest(hRequest, hdrs , strlen(hdrs), (PVOID)data.c_str(), data.length()))
{
DWORD blocksize = MAX_LEN;
DWORD received = 0;
std::string block(blocksize, 0);
while (InternetReadFile(hRequest, &block[0], blocksize, &received) && received)
{
block.resize(received);
result += block;
}
std::cout << result << std::endl;
}
return result;
}
How do you use WinInet with HTTPS?