我想从Internet Explorer获取cookie。所以我按照网络上的代码。我登录了一个网站,比如说bodis.com,然后我试着读取cookies
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 cookies。我已经登录google.com,确实有cookies。
我尝试了很多其他网站。 http://bodis.com http://www.bodis.com等等。没有用。