这里是使用 CookieContainer 获取 到 Cookie
string contentUrl = "https://home.cnblogs.com/u/xinjian/"; HttpWebRequest reqContent = (HttpWebRequest)WebRequest.Create(contentUrl); reqContent.Method = "GET"; reqContent.AllowAutoRedirect = false;//服务端重定向。一般设置false reqContent.ContentType = "application/x-www-form-urlencoded";//数据一般设置这个值,除非是文件上传
var cookie = new CookieContainer();
reqContent.CookieContainer = cookie; reqContent.CookieContainer.SetCookies(reqContent.RequestUri, cookies);//将登录的cookie值赋予此次的请求。 HttpWebResponse respContent = (HttpWebResponse)reqContent.GetResponse(); string html = new StreamReader(respContent.GetResponseStream()).ReadToEnd(); //获取到的cookie就在变量cookie中。
https://www.cnblogs.com/xinjian/p/6343367.html