C#基于WebBrowser获取cookie的实现方法
内容摘要
本文实例讲述了C#基于WebBrowser获取cookie的实现方法。分享给大家供大家参考,具体如下:
private void BtnOpenUrl_Click(object sender, EventArgs e)
{
if (txtUrl.Text
private void BtnOpenUrl_Click(object sender, EventArgs e)
{
if (txtUrl.Text
文章正文
本文实例讲述了C#基于WebBrowser获取cookie的实现方法。分享给大家供大家参考,具体如下:
private void BtnOpenUrl_Click(object sender, EventArgs e) { if (txtUrl.Text != "") { MywebBrowser.Url = new Uri(txtUrl.Text); } } private void BtnGetCookie_Click(object sender, EventArgs e) { CookieContainer myCookieContainer = new CookieContainer(); if (MywebBrowser.Document.Cookie != null) { string cookieStr = MywebBrowser.Document.Cookie; string[] cookstr = cookieStr.Split(';'); foreach (string str in cookstr) { string[] cookieNameValue = str.Split('='); Cookie ck = new Cookie(cookieNameValue[0].Trim().ToString(), cookieNameValue[1].Trim().ToString()); ck.Domain = "www.google.com"; myCookieContainer.Add(ck); } } }
希望本文所述对大家C#程序设计有所帮助。
代码注释