【发布时间】:2019-11-25 08:56:48
【问题描述】:
我在 post 请求中发送表单数据,我知道该请求返回 cookie,但我的 cookie 变量返回为空
如您所见,我已尝试使用 GetCookies,但我想知道是否可以在收到 200 响应时从 PostAsync 响应中过滤掉 cookie
CookieContainer cookies = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler();
handler.CookieContainer = cookies;
HttpClient client = new HttpClient(handler);
HttpContent content = new StringContent(JsonConvert.SerializeObject(formVals), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(targetURI.AbsoluteUri , content);
IEnumerable<Cookie> responseCookies = cookies.GetCookies(targetURI).Cast<Cookie>()
foreach (Cookie cookie in responseCookies)
result.Add(cookie);
我预计 2 个 cookie 会返回并存储在我的 responseCookies 容器中
【问题讨论】: