我正在使用VS2010
++ (来自.NET 4.0
)。System.Net.Http
Nuget
由于我无法理解的原因,我收到的会话 cookieHttpResponseMessage
不会自动保存在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 容器仍然是空的……为什么?