本文介绍了在 Windows Phone 中从 HttpWebResponse 的标头中读取 HttpOnly Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法从 Windows Phone 中的 HttpWebResponse 头中读取 HttpOnly Cookies?
Is there any way to read HttpOnly Cookies from Headers of HttpWebResponse in Windows Phone?
在我下面的代码中 "Set-Cookie" 不存在于 response.Cookies[]
In my code below "Set-Cookie" is not present in response.Cookies[]
我的代码
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 });
}
}
}
推荐答案
很遗憾,您无法直接访问 HttpOnly cookie.您可以使用 CookieContainer 将它们传递给不同的请求,但您无法读取它们.
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
这篇关于在 Windows Phone 中从 HttpWebResponse 的标头中读取 HttpOnly Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!