原文:从WebBrowser中取得Cookie 和 WebClient设置cookie!
从WebBrowser中取得Cookie 的代码
CookieContainer myCookieContainer = new CookieContainer();
string cookieStr = webBrowser1.Document.Cookie;
string[] cookstr = cookieStr.Split(';');
foreach (string str in cookstr)
{
string[] cookieNameValue = str.Split('=');
Cookie ck ].Trim ().ToString());
ck.Domain = "www.5ilrc.com";
myCookieContainer.Add(ck);
}
string cookieStr = webBrowser1.Document.Cookie;
string[] cookstr = cookieStr.Split(';');
foreach (string str in cookstr)
{
string[] cookieNameValue = str.Split('=');
Cookie ck ].Trim ().ToString());
ck.Domain = "www.5ilrc.com";
myCookieContainer.Add(ck);
}
WebClient设置cookie!
WebClient wc = new WebClient();
wc.Headers.Add("Cookie", "PHPSESSID=" + cookie + ";");
//~~~~~~~注意,这里是Cookie,不是Set-Cookie
]);
System.Text.UTF8Encoding converter = new System.Text.UTF8Encoding();
string str = converter.GetString(re);
wc.Headers.Add("Cookie", "PHPSESSID=" + cookie + ";");
//~~~~~~~注意,这里是Cookie,不是Set-Cookie
]);
System.Text.UTF8Encoding converter = new System.Text.UTF8Encoding();
string str = converter.GetString(re);