0
我使用HTTPWebRequest
/HTTPWebResponse
與網站(www.lockerz.com)進行交互。所以,我在網站上進行身份驗證:HttpWebResponse不包含cookies
HttpWebRequest webRequest = (HttpWebRequest) HttpWebRequest.Create("http://www.lockerz.com/auth/login");
byte[] bytes = Encoding.ASCII.GetBytes("handle=" + textBoxEmail.Text + "&password=" + textBoxPassword.Text);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
webRequest.ContentLength = bytes.Length;
Stream os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
然後我得到的迴應:
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
我看使用查爾斯的請求\響應和它說,在響應必須有餅乾,但是當我嘗試製作一個cookies列表時,我知道它沒有cookie!
foreach(Cookie c in webResponse.Cookies) {
writeToLog("Cookie Name: " + c.Name + " Value: " + c.Value);
cc.Add(c);
}
我試着加入的CookieContainer,但它不反正工作。
您是否嘗試附加CookieContainer? http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer.aspx – 2011-02-05 13:01:43