vba 设置/获取 Web Cookie
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/345485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set/Get Web Cookies
提问by Curtis Inderwiesche
Assuming I am not running server side scripting of any kind, how can I set
and get
a cookie from within VBA code?
假设我没有运行任何种类的服务器端脚本,我怎么能set
和get
从VBA代码中的一个cookie?
回答by Gunny
I saw a posting about this that might help for setting the cookie:
我看到一个关于这个的帖子,可能有助于设置 cookie:
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.
不确定是否获取 cookie - 主要海报之一提到 XmlHttp 出于安全原因删除了 cookie。
Hope that might get you started!
希望这可以让你开始!