6

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

Community
  • 1
  • 1
jeon
  • 123
  • 1
  • 3
  • 15

1 Answers1

6

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
Robin Mackenzie
  • 18,801
  • 7
  • 38
  • 56
  • 2
    It's not just a rumor. MSXML strips the response and removes the cookies for security reasons. – TCN Jun 24 '17 at 08:09