一开始使用WebBrowser.Document.Cookie获取,怎么获取这个值都是null,但是使用http分析工具抓到的包里就都能够看到ASP.NET_SessionId等Cookie值
用了很多办法都不行,下面的方法可以,Mark~
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref int pcchCookieData, int dwFlags, object lpReserved); private static string GetCookieString(string url) { // Determine the size of the cookie int datasize = 256; StringBuilder cookieData = new StringBuilder(datasize); if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null)) { if (datasize < 0) return null; // Allocate stringbuilder large enough to hold the cookie cookieData = new StringBuilder(datasize); if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null)) return null; } return cookieData.ToString(); }
《“获取WebBrowser中的Cookies(包含ASP.NET_SessionId等)”》 有 1 条评论
thanks for you message