在 .net core 使用 httpclient 时,可能会有会话 cookie 被保存的情况处理
在调用其它接口时发现,请求过程的 Cookie 被保存了下来,但是其实是不想要的
似乎在 .net core 的 httpclient 请求机制中,是有 HttpClientHandler 缓存的机制
这时候需要修改 HttpClientHandler 的配置
方法1,直接创建新的 HttpClient :
var handler = new HttpClientHandler() { UseCookies = false }; var httpClient = new HttpClient(handler);
方法2,通过 IHttpClientFactory 创建:
services.AddHttpClient("configured-inner-handler") .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler() { UseCookies = false });
更多:
https://www.cnblogs.com/edison0621/p/11224890.html
输了你,赢了世界又如何...