zoukankan      html  css  js  c++  java
  • C#利用WebBrowser获取完整COOKIE

    代码:

    http://www.cnblogs.com/hsapphire/archive/2010/09/10/1823384.html

    http://blog.csdn.net/attilax/article/details/8595036

      [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
            static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref System.UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved);
    
            [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
            static extern int InternetSetCookieEx(string lpszURL, string lpszCookieName, string lpszCookieData, int dwFlags, IntPtr dwReserved);
      WebBrowser browser = (WebBrowser)sender;
                HtmlDocument doc = browser.Document;
    
                this.Text = doc.Title;
                string url = doc.Url.AbsoluteUri;
                //string cookies2 = GetCookies(url);
    
                //保留cookie
               // cookieString = doc.Cookie;
                cookieString = GetCookies(url);
     
    private static string GetCookies(string url) { uint datasize = 256; StringBuilder cookieData = new StringBuilder((int)datasize); if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x2000, IntPtr.Zero)) { if (datasize < 0) return null; cookieData = new StringBuilder((int)datasize); if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, IntPtr.Zero)) return null; } return cookieData.ToString(); }
  • 相关阅读:
    系统数据库如何恢复Master数据库
    在Orderby子句中使用CASE 语句
    SQL NOTECURSOR
    MVC 中静态文件部分动态化
    SQL NOTCTE
    Get data style from Excel
    SQL NOTPARTITION
    LAMDA表达式学习
    SQL NOTEVARIABLE
    起II6.0中使用windows2003自带的虚拟主机管理系统
  • 原文地址:https://www.cnblogs.com/ryhan/p/4506083.html
Copyright © 2011-2022 走看看