0

Is it possible to access response header from InternetExplorer.Application in VB/VBA/VB.net?

myIE = CreateObject("InternetExplorer.Application")
    .Visible = False
    .Navigate "http://someserver/resources/postrequest"

Give this code, how would i get a hold of the header, or more specifically, the cookie.

This is very useful for making web service calls using MSXML2.ServerXMLHTTP to servers that required cookie for authentication. Once you obtain the cookie it could be passed in the header for the subsequent web service calls.

1 Answer 1

1
Private Declare Sub Sleep Lib "kernel32" _
    (ByVal dwMilliseconds As Long)

Private Function getCookie()
    Dim myIe As Object
    Set myIe = CreateObject("InternetExplorer.Application")
    myIe.Visible = False
    myIe.Navigate "http://someurl"
    Do While myIe.Busy
        Sleep 20
    Loop
    getCookie= myIe.Document.cookie
End Function

For this to work on 64 bit, the PtrSafe keyword needs to be added to the Sleep definition:

Private Declare PtrSafe Sub Sleep Lib "kernel32" _
    (ByVal dwMilliseconds As Long)
1
  • As long as it's not a "HTTPOnly" cookie Commented Mar 13, 2012 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.