【发布时间】:2010-11-22 18:08:42
【问题描述】:
我正在尝试获取标头“Set-Cookie”或访问 cookie 容器,但 Set-Cookie 标头不可用。 cookie 在响应标头中,但不在客户端请求对象中。 我正在使用
注册ClientHttp堆栈
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>
我的回调代码包含如下内容:
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 标头。
对可能出现的问题有什么建议吗?
【问题讨论】:
-
我在 WP7 上的 HttpWebResponses 中似乎也缺少“Set-Cookie”标头。
标签: c# windows-phone-7 cookies httpwebrequest httpwebresponse