我创建了以下代码,据我所知应该可以正常工作?它根本没有收到任何cookie,我已经用线鲨进行了双重检查,并且正在返回cookie ...这是在Windows Phone 7上开发的。
byte[] content = GetLoginRequestContent(username, password);
CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(LoginUri);
httpWebRequest.ContentType = AuthContentType;
httpWebRequest.Method = "POST";
httpWebRequest.Headers["referer"] = LoginRequestReferer;
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.Headers[HttpRequestHeader.ContentLength] = content.Length.ToString();
httpWebRequest.BeginGetRequestStream(async1 =>
{
using (Stream stream = httpWebRequest.EndGetRequestStream(async1))
stream.Write(content, 0, content.Length);
httpWebRequest.BeginGetResponse(async2 =>
{
HttpWebResponse rep = (HttpWebResponse)httpWebRequest.EndGetResponse(async2);
CookieCollection cookies = rep.Cookies;
using (Stream stream = rep.GetResponseStream())
using (StreamReader sr = new StreamReader(stream))
{
String contentX = sr.ReadToEnd();
//if blah blah
}
}, null);
}, null);
答案 0 :(得分:2)
如果cookie标有HttpOnly(通常是会话cookie的情况),出于安全原因,您无法访问客户端脚本。它被发送到客户端,客户端在后续请求中将其重新发送到服务器(如果它拥有cookie容器),但是您无法在客户端上读取它的值。