這是我設置Cookie數據並傳遞Web請求的方式。當我使用fiddler檢查網站的回覆時,我發現cookies沒有數據,到期日數據將設置爲1900年1月1日。任何幫助將不勝感激。如果下面的代碼不清楚,請告訴我,或者您需要更多信息來回答我的問題。謝謝。Cookies作爲WebRequest的一部分發送時不保留任何數據
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();
}
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –