winHTTP GET request C++

11,353

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.

Share:
11,353
Ilia Choly
Author by

Ilia Choly

Favourite Languages: Go TypeScript Python C Lisp Interests: Networking Distributed/Parallel Computing Compilers Security Social Twitter Facebook Github

Updated on June 04, 2022

Comments

  • Ilia Choly
    Ilia Choly almost 2 years

    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

    • SteelBytes
      SteelBytes about 14 years
      I don't know the answer, but I am curious as to why you wish this?
    • jpyllman
      jpyllman about 14 years
      Since you should send Host: site.com in a separate line and only send path in the GET? Actually after reading the RFC it say if site stated in the GET URI Host: should be ignored.
    • Ilia Choly
      Ilia Choly about 14 years
      atm my code is a c/p from msdn msdn.microsoft.com/en-us/library/aa384270%28VS.85%29.aspx I already tried setting the url to /index.html and then manually setting the Host: header but it didn't work.
    • Jonathan
      Jonathan almost 6 years
      Maybe you have some non-transparent proxy configured on the machine (either local like Fiddler or corporate) - in that case, the request will have the full uri