【发布时间】:2013-02-04 05:57:57
【问题描述】:
我正在使用VS2010 +.NET 4.0 + System.Net.Http(来自Nuget)。
由于我无法理解的原因,我在 HttpResponseMessage 中收到的会话 cookie 不会自动保存在 HttpClient CookieContainer 中。
这是我的代码的样子:
CookieContainer cookies = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler();
handler.CookieContainer = cookies;
HttpClient client = new HttpClient(handler);
Uri site = new Uri("https://www.mywebsite.com");
var response1 = client.SendAsync(new HttpRequestMessage(HttpMethod.Get,site)).Result;
我可以在响应标头中看到以下内容:
Set-Cookie: JSESSIONID=FC8110E434C2C6DAB78B4E335024A639; Path=/member; Secure
但是我的 cookie 容器仍然是空的……为什么?
【问题讨论】:
标签: c# cookies httpclient