我试图在成功 POST 后获取响应中设置的 cookie。如何从结果中获取 cookie?
var baseAddress = new Uri("http://rtchatserver");
var cookieContainer = new CookieContainer();
using (var postHandler = new HttpClientHandler() { CookieContainer = cookieContainer })
using (var client = new HttpClient(postHandler) {BaseAddress = baseAddress})
{
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("UserName", "bar"),
new KeyValuePair<string, string>("Password", "bazinga"),
new KeyValuePair<string, string>("__RequestVerificationToken", token),
new KeyValuePair<string, string>("returnUrl", "http://google.com"),
});
cookieContainer.Add(baseAddress, responseCookies.FirstOrDefault());
var result = client.PostAsync("/account/login", content).Result;
result.EnsureSuccessStatusCode();
}