【发布时间】:2013-03-08 18:52:28
【问题描述】:
我希望下面的代码会产生一个非零值:
var webRequest = (HttpWebRequest) WebRequest.Create(loginUrl);
var webResponse = (HttpWebResponse)webRequest.GetResponse();
Console.WriteLine(webResponse.Cookies.Count);
但webRespone.Cookies 中似乎没有显示任何 cookie。我很肯定 cookie 就在那里,因为我正在用 Fiddler 嗅探数据。这是我得到的回复:
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
Set-Cookie: __Abc=Def; path=/; HttpOnly
PS-ResponseTime: 00:00:00.0624001
PS-Build: 2013-03-19-11-36-59
PS-Node: 02
Date: Tue, 19 Mar 2013 21:14:51 GMT
Content-Length: 57872
这与cookie是HttpOnly这一事实有什么关系吗?
编辑
看来我可以让他们通过HttpWebRequest 的CookieContainer,如果我打算继续进行一系列请求/响应,这肯定很有用。但是为什么我不能通过HttpWebResponse.Cookies 字段访问它们呢?
谢谢
【问题讨论】:
-
你是如何得到 Set-Cookie 的:__Abc=Def;路径=/; HttpOnly 在 http 响应中?
标签: c# httpwebrequest httprequest httpresponse httpwebresponse