Set/Get Web Cookies

2019-08-02 05:55发布

问题:

Assuming I am not running server side scripting of any kind, how can I set and get a cookie from within VBA code?

回答1:

I saw a posting about this that might help for setting the cookie:

link text

Here is his code snippet:

Sub test()
Dim w As New WinHttp.WinHttpRequest
Dim t As String, qs As String
qs = "this=that&more=less"
w.Open "POST", "http://www.comparity.net/perl/form.pl?a=b", False
w.setRequestHeader "Cookie", "one=foo"
w.setRequestHeader "Cookie", "two=bar"
w.send qs
t = w.responseText
WriteTextFile "c:\test.html", t
Debug.Print w.Status
Debug.Print t
End Sub

Not sure about getting the cookie - one of the main posters mentions that XmlHttp strips out cookies for security reasons.

Hope that might get you started!