这就是我设置 cookie 数据并传递 Web 请求的方式。当我使用 fiddler 检查网站的响应时,我看到 cookie 没有数据,并且到期数据设置为 1900 年 1 月 1 日。任何帮助将不胜感激。如果以下代码中有不清楚的地方,或者您需要更多信息来回答我的问题,请告诉我。谢谢。
System.Net.Cookie userType =
new System.Net.Cookie("CUserType","subscriber", "/", "www.DOMAIN_NAME.com");
userType.Expires = DateTime.Now.AddYears(1);
System.Net.Cookie dUserType =
new System.Net.Cookie("dCUserType", "subscriber", "/", "www.DOMAIN_NAME.com");
dUserType.Expires = DateTime.Now.AddYears(1);
System.Net.CookieContainer cookieContainer = new System.Net.CookieContainer();
cookieContainer.Add(userType);
cookieContainer.Add(dUserType);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(URL);
webRequest.Proxy = new WebProxy("127.0.0.1", 8888);
webRequest.Referer = "http://DOMAIN_NAME/search/index.aspx?lid=3";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Date = DateTime.Now;
webRequest.CookieContainer = cookieContainer;
string result;
using (var stream = webRequest.GetResponse().GetResponseStream())
using (var reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}