Search notes:

Windows HTTP Services

Apparently, WinHttp.WinHttpRequest.5.1 allows for greater control over HTTP requests than MSXML2.ServerXMLHTTP.

Adding reference for Microsoft WinHTTP Services

In order to programatically add the reference in a VBA project, the following code might be used:
call application.VBE.activeVBProject.references.addFromGuid("{662901fc-6951-4854-9eb2-d9a2570f2b2e}", 5, 1)
Alternatively, the reference can also be added from the DLL that implements the functionality
application.VBE.activeVBProject.references.addFromFile "C:\WINDOWS\system32\winhttpcom.dll"

GET request

The following Visual Basic for Application example tries to make a HTTP GET request.
option explicit

sub main() ' {

    dim httpReq as new winHTTP.winHTTPRequest

    httpReq.setTimeouts 20000, 20000, 20000, 20000

    httpReq.open "GET", "http://renenyffenegger.ch/", false

    debug.print (httpReq.Option(WinHttpRequestOption_UserAgentString))
  ' Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)

  ' httpReq.option(winHttpRequestOption_UserAgentString)              = "...."
    httpReq.option(winHttpRequestOption_EnableRedirects)              = true
    httpReq.option(winHttpRequestOption_EnableHttpsToHttpRedirects)   = true
  ' httpReq.option(winHttpRequestOption_SslErrorIgnoreFlags)          = 13056 ' Ignore all errors
  ' httpReq.option(winHttpRequestOption_EnablePassportAuthentication) = true

    httpReq.send

    if err.number <> 0 then ' {
       debug.print ("Could not perform http request")
       debug.print (err.number & ": " & err.source)
       debug.print (err.description)
       exit sub
    end if ' }

    if httpReq.Status <> 200 then
       debug.print (httpReq.status & ": " & httpReq.statusText)
    end if

    debug.print (httpReq.responseText)

end sub ' }
Github repository about-VBA, path: /object-libraries/Windows-HTTP-Services/GET.bas
Compare with the corresponding MSXML example.

POST request

A POST request is formulated similarly to a GET request with the POST's body passed as parameter to the .send method.

setRequestHeader

httpReq.setRequestHeader "Content-Type", "text/html; charset=UTF-8"
httpReq.setRequestHeader "Cookie"      , "ReqClientId=4c8d9896-6321-4f05-3aef-737536cd1882"
Apparently, setRequestHeader can only be called after open() was called.

setAutoLogonPolicy

setAutoLogonPolicy sets the automatic logon policy to one of the following possible values:
httpReq.setAutoLogonPolicy autoLogonPolicy_always
Setting the logon policy is sometimes required if the HTTP server requires authentication. (If the server requests the client to be authenticated, it sends the 401 status code.

See also

Useful object libraries
HTTP

Index