Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

winHTTP GET request C++

I'll get right to the point.

  • This is what a browser request looks like

    GET /index.html HTTP/1.1

  • This is what winHTTP does

    GET http://site.com/index.html HTTP/1.1

Is there any I can get the winHTTP request to be the same format as the regular one? I'm using VC++ 2008 if it makes any difference

like image 931
Ilia Choly Avatar asked Oct 15 '25 15:10

Ilia Choly


1 Answers

Your code should look like this:

// Specify an HTTP server.
if (hSession)
    hConnect = WinHttpConnect( hSession, L"www.example.com",
                               INTERNET_DEFAULT_HTTP_PORT, 0);

// Create an HTTP request handle.
if (hConnect)
    hRequest = WinHttpOpenRequest( hConnect, L"GET", L"/path/resource.html",
                                   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);

Can you post these three calls from your code?

Note that the full URL is split in two - the host name is specified in the WinHttpConnect call, but the relative resource path is specified in the WinHttpOpenRequest call (as the pwszObjectName parameter). Based on your comment, it seems you are specifying the full URL in the WinHttpConnect call.

like image 78
Franci Penov Avatar answered Oct 17 '25 04:10

Franci Penov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!