HttpWebRequest和响应设置Cookie头不被解析(WP7) [英] HttpWebRequest and Set-Cookie header in response not parsed (WP7)

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

问题描述

我想获得头设置Cookie,或访问cookie的容器,但在Set-Cookie头不可用。
中的cookie是在响应头,但它不存在于客户端请求的对象。
我注册使用

ClientHttp 堆栈

 布尔httpResult = WebRequest.RegisterPrefix(HTTP://,WebRequestCreator.ClientHttp); 

下面是响应:

  HTTP / 1.1 200 OK 
的Content-Type:application / xml进行;字符集= UTF-8
连接:保持活动
状态:200
的X技术,通过:Phusion的客运(mod_rails / mod_rack)3.0.0.pre4
的ETag: 39030a9c5a45a24e485e4d2fb06c6389
客户端版本:312,105,0,0
的X片长:44
的Content-Length:1232
的Set-Cookie:_CWFServer_session = [这是会话数据];路径= /;仅Http
缓存控制:私人,最大年龄= 0,必重新验证
服务器:nginx / 0.7.67 +的Phusion客运3.0.0.pre4(mod_rails / mod_rack)

< XML版本=1.0编码=UTF-8>?;
<使用者>

< /使用者名称>



我的回调代码中包含类似:

  VAR的WebRequest =(HttpWebRequest的)result.AsyncState; 
生= webRequest.EndGetResponse(结果)作为HttpWebResponse;
的foreach(曲奇℃的webRequest.CookieContainer.GetCookies(webRequest.RequestUri))
{
Console.WriteLine(曲奇['+ c.Name +']:+ C 。值);
}



我也试着看标题,但设置Cookie头ISN目前无论是在响应吨。



这可能是什么问题?


解决方案<任何建议/ DIV>

尝试明确地传递一个新的CookieContainer:

 的CookieContainer集装箱=新的CookieContainer(); 
container.Add(新的URI(HTTP:// yoursite),新的Cookie(名,价值));
HttpWebRequest的要求=(HttpWebRequest的)WebRequest.Create(HTTP:// yoursite);
request.CookieContainer =容器;
request.BeginGetResponse(新的AsyncCallback(的GetData),请求);


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);

Here's the response:

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);
}

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?

解决方案

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和响应设置Cookie头不被解析(WP7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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