Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Microsoft.XMLHTTP setRequestHeader not sending cookie

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

like image 557
jeon Avatar asked Jul 11 '16 12:07

jeon


1 Answers

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
like image 183
Robin Mackenzie Avatar answered Nov 14 '22 21:11

Robin Mackenzie