Method for obtaining Cookie information of IE browser

  • 2021-07-13 04:23:41
  • OfStack

Many people don't know how to get Cookie information in IE browser. In fact, the way to get Cookie is very simple, and they only need to call InternetGetCookie, which is API.

InternetGetCookie is declared as follows:

Private Declare Function InternetGetCookie Lib "wininet.dll" Alias "InternetGetCookieA" (ByVal lpszUrlName As String, ByVal lpszCookieName As String, ByVal lpszCookieData As String, lpdwSize As Long) As Boolean

We want to get Cookie information under the domain name www. baidu. com, which can be written as follows:

Dim buffer As String * 8096If InternetGetCookie ("http://www. baidu. com", vbNullString, buffer, 8096) Then MsgBox "The Cookie information obtained is as follows:" & vbCrLf & bufferEnd If

Get results:

The obtained Cookie information is as follows: bdshare_firstime=1385336980826; sug=3; sugstore=1; BD_TMP_CK=true; BAIDUID=F1F6DA77AD0E469EEF3301C98F1CB0A1: FG=1; cflag=65535% 3A1; BAIDU_WISE_UID=wapp_1385534156727_907; locale = zh; bdime=0; NBID=D3EEB391CF4DCDA2ED0B6035E872886D: FG=1

There is a disadvantage in using InternetGetCookie to obtain Cookie information, because it cannot obtain Cookie with HTTP_ONLY tag.

The solution to this problem is to use InternetGetCookie, an extended version of API, InternetGetCookieEx, but it also has problems, and some versions of IE are not well supported.

InternetGetCookieEx is declared as follows:

Private Const INTERNET_COOKIE_HTTPONLY As Integer = 8192Private Declare Function InternetGetCookieEx Lib "wininet.dll" Alias "InternetGetCookieExA" (ByVal url As String, ByVal cookieName As String, ByVal cookieData As String, ByRef size As Integer, ByVal flags As Integer, ByVal pReserved As Long) As Boolean

The invocation method is similar:

Dim buffer As String * 8096If InternetGetCookieEx ("http://www. baidu. com", vbNullString, buffer, 8096, INTERNET_COOKIE_HTTPONLY, 0) Then MsgBox "The obtained Cookie information is as follows:" & vbCrLf & bufferEnd If

Get results:

The obtained Cookie information is as follows: bdshare_firstime=1385336980826; sug=3; sugstore=1; BD_TMP_CK=true; BAIDUID=F1F6DA77AD0E469EEF3301C98F1CB0A1: FG=1; cflag=65535% 3A1; BAIDU_WISE_UID=wapp_1385534156727_907; locale = zh; bdime=0; NBID=D3EEB391CF4DCDA2ED0B6035E872886D: FG=1; BDUSS=EdwblA4akE5NjV-N3RPZFdjcW52VkJQQXBvbXhRMm5PaEXucy05am1MYkdjY0pTQVFBQUFBJCQAAAAAAAAAAAEAAAXDmn4UdDJubgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMbkmlLS5JpSe

These two API have their own advantages and disadvantages, which one to use depends on the specific situation.


Related articles: