Reputation: 165
I have created the following code, which as far as Im aware should work fine? It is not receiving any cookies at all, I have double checked with wire shark and the cookies are being returned... this is being developed on 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);
Upvotes: 0
Views: 2950
Reputation: 1038780
If the cookie is marked with HttpOnly (which is often the case with session cookies) you cannot access them it client side scripting for security reasons. It is sent to the client, the client resends it to the server (if it posses a cookie container) on subsequent requests, but you cannot read its value on the client.
Upvotes: 2