c# WebBrowser获取cookie

 1         private void BtnOpenUrl_Click(object sender, EventArgs e)
 2         {
 3             if (txtUrl.Text != "")
 4             {
 5                 MywebBrowser.Url = new Uri(txtUrl.Text);
 6             }
 7         }
 8 
 9         private void BtnGetCookie_Click(object sender, EventArgs e)
10         {
11             CookieContainer myCookieContainer = new CookieContainer();
12             if (MywebBrowser.Document.Cookie != null)
13             {
14                 string cookieStr = MywebBrowser.Document.Cookie;
15                 string[] cookstr = cookieStr.Split(';');
16                 foreach (string str in cookstr)
17                 {
18                     string[] cookieNameValue = str.Split('=');
19                     Cookie ck = new Cookie(cookieNameValue[0].Trim().ToString(), cookieNameValue[1].Trim().ToString());
20                     ck.Domain = "www.google.com";
21                     myCookieContainer.Add(ck);
22                 }
23             }
24         }

 

posted @ 2013-11-05 12:30  宁静.致远  阅读(16941)  评论(0编辑  收藏  举报