我想从 Internet Explorer 获取 cookie。所以我遵循网络上的代码。我登录到一个网站,比如 bodis.com,然后我尝试读取 cookie
Private Declare Function InternetGetCookieEx Lib "wininet.dll" Alias "InternetGetCookieExA" (url As String, cookieName As String, cookieData As System.Text.StringBuilder, ByRef size As Integer, dwFlags As Int32, lpReserved As IntPtr) As Boolean
Private Const InternetCookieHttponly As Int32 = &H2000
Public Function GetUriCookieContainer1(uri As Uri) As System.Net.CookieContainer
Dim cookies As System.Net.CookieContainer = Nothing
' Determine the size of the cookie
Dim datasize As Integer = 8192 * 16
Dim cookieData As New System.Text.StringBuilder(datasize)
Dim sURL = uri.ToString
sURL = "http://google.com" ' for simplicity sake
If Not InternetGetCookieEx(sURL, Nothing, cookieData, datasize, InternetCookieHttponly, IntPtr.Zero) Then
If datasize < 0 Then 'always return 0 even though I am sure there is cookies
Return Nothing
End If
...
为什么datasize总是0。我知道有cookie。我输入 sURL="http://google.com" 以确保每个人都明白我想要 google.com cookie。我已经登录到 google.com 并且确实有 cookie。
我尝试了很多其他网站。http://bodis.com http://www.bodis.com等。没有工作。