0

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?

ahmad
  • 9
  • 5
  • 1
    You don't just stick `INTERNET_FLAG_SECURE` everywhere, but only where the documentation says it should go. It's not a valid flag for `InternetOpen`, nor for `InternetConnect`; it should be passed to `HttpOpenRequest`. That accepted answer you cite even says so: "`INTERNET_FLAG_SECURE` should be used in the flags for `HttpOpenRequest`, not `InternetConnect`". As to "not showing any errors" - how do you know that? You don't check any API calls for errors. – Igor Tandetnik Dec 25 '21 at 02:45
  • @IgorTandetnik i do check for api calls but i don't see anything – ahmad Dec 25 '21 at 07:31
  • What do you expect to see? Your program doesn't produce any diagnostic output when any of the API calls fail. E.g. the documentation for `HttpSendRequest` says: "Returns `TRUE` if successful, or `FALSE` otherwise. To get extended error information, call `GetLastError`." This tells you what you need to do to know more about why the call failed. – Igor Tandetnik Dec 25 '21 at 13:49
  • @IgorTandetnik using `GetLastError` gives me a zero which i know means there is an error, on the server side not loggin happens and the console running the webapp does not have any requests with the ip address for the machine running that function – ahmad Dec 25 '21 at 19:17

0 Answers0