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
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 ' }
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:
-
autoLogonPolicy_always
-
autoLogonPolicy_never
-
autoLogonPolicy_onlyIfBypassProxy
httpReq.setAutoLogonPolicy autoLogonPolicy_always