VBA Microsoft.XMLHTTP setRequestHeader not sending cookie

13,005

There's a rumour on Google that you have to use the WinHTTP object here and not MSXML2. E.g.:

Option Explicit

    Sub Test()

        Dim objRequest As Object
        Dim strResponse As String
        Dim blnAsync  As Boolean

        Set objRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
        blnAsync = True

        With objRequest
            .Open "POST", "http://www.comparity.net/perl/form.pl", blnAsync
            .setRequestHeader "Cookie", "timtam=penguin"
            .send
            .WaitForResponse
            strResponse = .responseText
            Debug.Print strResponse
            Debug.Print .Status
        End With

    End Sub
Share:
13,005
jeon
Author by

jeon

Updated on June 11, 2022

Comments

  • jeon
    jeon almost 2 years

    My VBA code send every headers except for Cookie information.

    Dim oXMLHttpRequest As Object
    Set oXMLHttpRequest = CreateObject("Microsoft.XmlHttp")
    oXMLHttpRequest.setRequestHeader "Accept", "text/html, application/xhtml+xml, */*"
    oXMLHttpRequest.setRequestHeader "Accept-Language", "ko-KR"
    oXMLHttpRequest.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
    oXMLHttpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    oXMLHttpRequest.setRequestHeader "Accept-Encoding", "gzip, deflate"
    oXMLHttpRequest.setRequestHeader "Connection", "Keep-Alive"
    oXMLHttpRequest.setRequestHeader "DNT", "1"
    oXMLHttpRequest.setRequestHeader "Cookie", "xxx=yyy"
    oXMLHttpRequest.send[enter image description here][1]
    

    As you see in the Capture link below, Cookie: xxx=yyy is missing.. I have no clue. Please help me. Thank you.

    Fiddler capture:

    Fiddler capture

  • jony
    jony almost 7 years
    It's not just a rumor. MSXML strips the response and removes the cookies for security reasons.