未解析响应中的 HttpWebRequest 和 Set-Cookie 标头 (WP7) [英] HttpWebRequest and Set-Cookie header in response not parsed (WP7)

查看:24
本文介绍了未解析响应中的 HttpWebRequest 和 Set-Cookie 标头 (WP7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取标头Set-Cookie"或访问 cookie 容器,但 Set-Cookie 标头不可用.cookie 位于响应标头中,但不在客户端请求对象中.我正在使用

I am trying to get the header "Set-Cookie" or access the cookie container, but the Set-Cookie header is not available. The cookie is in the response header, but it's not there in the client request object. I am registering the ClientHttp stack using

bool httpResult = WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);

回复如下:

HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8
Connection: keep-alive
Status: 200
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.0.pre4
ETag: "39030a9c5a45a24e485e4d2fb06c6389"
Client-Version: 312, 105, 0, 0
X-Runtime: 44
Content-Length: 1232
Set-Cookie: _CWFServer_session=[This is the session data]; path=/; HttpOnly
Cache-Control: private, max-age=0, must-revalidate
Server: nginx/0.7.67 + Phusion Passenger 3.0.0.pre4 (mod_rails/mod_rack)

<?xml version="1.0" encoding="UTF-8"?>
<user>
...
</user>

我的回调代码包含如下内容:

My callback code contains something like:

var webRequest = (HttpWebRequest)result.AsyncState;
raw = webRequest.EndGetResponse(result) as HttpWebResponse;
foreach (Cookie c in webRequest.CookieContainer.GetCookies(webRequest.RequestUri))
{
    Console.WriteLine("Cookie['" + c.Name + "']: " + c.Value);
}

我也尝试查看标头,但响应中也不存在 Set-Cookie 标头.

I've also tried looking at the headers but Set-Cookie header isn't present in the response either.

对可能出现的问题有什么建议吗?

Any suggestions on what may be the problem?

推荐答案

尝试显式传递一个新的 CookieContainer:

Try explicitly passing a new CookieContainer:

CookieContainer container = new CookieContainer();
container.Add(new Uri("http://yoursite"), new Cookie("name", "value"));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://yoursite");
request.CookieContainer = container;
request.BeginGetResponse(new AsyncCallback(GetData), request);

这篇关于未解析响应中的 HttpWebRequest 和 Set-Cookie 标头 (WP7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆