我尝试使用此代码从网站获取 cookie
CookieCollection cookies = new CookieCollection();
CookieContainer cooki = new CookieContainer();
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(weburl.Text);
request.CookieContainer = cooki;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader read = new StreamReader(response.GetResponseStream());
request.CookieContainer = cooki;
request.CookieContainer.Add(cookies);
cookies = response.Cookies;
if(response.Cookies != null && response.Cookies.Count != 0)
{
foreach(Cookie c in response.Cookies)
listBox2.Items.Add(c.ToString());
}
else
listBox2.Items.Add("No Cookies");
但是,当我为http://www.cloob.com之类的网站尝试此操作时,什么也没有发生。
我在 C# 中通过 webbrowser 尝试了这个站点并尝试了这段代码
string cooki = webbrowser1.Document.Cookie.tostring();
我得到了很多这样的信息:
饼干=LMOT=1343810524;IdM=否;__utma=204761026.19745671.1343776441.1343805546.1343810526.4;__utmz=204761026.1343776441.1.1.utmccn=(直接)|utmcsr=(直接)|utmcmd=(无); CR=%7B%22online_count%22:%5B%7B%22count%22:8059,%22status%22:%22available%22%7D,%7B%22count%22:%221204%22,%22status%22:% 22invisible%22%7D,%7B%22count%22:%2276%22,%22status%22:%22busy%22%7D%5D%7D; m_id=1343781310_7982757; LCCT=1343809271;__utmb=204761026; __utmc=204761026
现在我怎样才能通过 webrequest 得到这个?