我的VBA代码发送除Cookie信息之外的每个标题。
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]
正如您在下面的Capture链接中看到的,Cookie:xxx = yyy缺失.. 我没有线索。请帮我。 谢谢。
Fiddler捕获:
答案 0 :(得分:2)
Google上有一个rumour,你必须在这里使用WinHTTP对象,而不是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