问题
Is there any way to read HttpOnly Cookies from Headers of HttpWebResponse in Windows Phone?
In my code below "Set-Cookie" is not present in response.Cookies[]
My code
HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
// End the get response operation
using (HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult))
{
Stream streamResponse = response.GetResponseStream();
// But Set-Cookie is not present here as its HttpOnly
var cookies = response.Cookies["Set-Cookie"];
using (StreamReader streamReader = new StreamReader(streamResponse))
{
String Response = streamReader.ReadToEnd();
streamResponse.Close();
streamReader.Close();
response.Close();
// Call the response callback
if (Callback != null)
{
Callback(this, new EventArgs1() { Response = Response, Cookie = cookies });
}
}
}
回答1:
Unfortunately you cannot access HttpOnly cookies directly. You can pass them to different requests using a CookieContainer, but you cannot read them.
CookieContainer container = new CookieContainer();
HttpWebRequest request = CreateRequest();
request.CookieContainer = container;
//do some requests
来源:https://stackoverflow.com/questions/8927755/reading-httponly-cookies-from-headers-of-httpwebresponse-in-windows-phone