Using InternetExplorer.Application to get a session cookie
Assuming I've used InternetExplorer.Application to pro grammatically navigate to a website that in turn has set a session cookie, how can I access the value of that cookie (that is only in memory at this point)?
The only way I can think of would involve adding some client side scripting to the Document.Body.InnerHTML and then call that scripting with .Navigate("javascript:functionName()"). Assuming that function would in turn create an element with the value of the cookie in question that I could retrieve at that point.
However, this seems convoluted and I've not yet been successful. Please tell me there's a simpler way.
EDIT: My question was answered in another forum by Rick Strahl. Apparently I didn't read the documentation close enough because there is a document.cookie property开发者_JS百科 that will give me the answer without any convoluted process.
Now, do I down vote my own question? :)
For completeness sake, I'm putting my answer that I added in the question above as the answer here.
The answer is simple, there is a document.cookie property that will give the value I was looking for. The difficulty, I found, is in finding the official documentation for the DOM accessible via the InternetExplorer.Application object. Intellisense in Visual Studio wasn't showing this property (at least for me) so I assumed there wasn't one.
I think I found the official document for the DOM here:
http://msdn.microsoft.com/en-us/library/ms535862(v=VS.85).aspx
and the cookie property specifically here:
http://msdn.microsoft.com/en-us/library/ms533693(v=vs.85).aspx
Hope this helps someone avoid chasing their tail in the future.
Thanks to brettbaggott for pointing me at the right direction. Here is the code for those who are interested:
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
精彩评论