一个离开.NET的程序员

ryhan

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

代码:

 

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(); }

 

posted on 2015-05-15 15:31  ryhan  阅读(5536)  评论(0编辑  收藏  举报