vba 如何从 InternetExplorer.Application 访问 cookie
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9690947/
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
How can I access cookie from InternetExplorer.Application
提问by ltfishie
Is it possible to access response header from InternetExplorer.Application in VB/VBA/VB.net?
是否可以从 VB/VBA/VB.net 中的 InternetExplorer.Application 访问响应头?
myIE = CreateObject("InternetExplorer.Application")
.Visible = False
.Navigate "http://someserver/resources/postrequest"
Give this code, how would i get a hold of the header, or more specifically, the cookie.
给这个代码,我将如何获得标题,或者更具体地说,cookie。
This is very useful for making web service calls using MSXML2.ServerXMLHTTP to servers that required cookie for authentication. Once you obtain the cookie it could be passed in the header for the subsequent web service calls.
这对于使用 MSXML2.ServerXMLHTTP 向需要 cookie 进行身份验证的服务器进行 Web 服务调用非常有用。获得 cookie 后,它可以在标头中传递以供后续 Web 服务调用使用。
回答by ltfishie
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Private Function getCookie()
Dim myIe As Object
Set myIe = CreateObject("InternetExplorer.Application")
myIe.Visible = False
myIe.Navigate "http://someurl"
Do While myIe.Busy
Sleep 20
Loop
getCookie= myIe.Document.cookie
End Function
For this to work on 64 bit, the PtrSafe
keyword needs to be added to the Sleep
definition:
要使其在 64 位上工作,PtrSafe
需要将关键字添加到Sleep
定义中:
Private Declare PtrSafe Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)