在调用其它接口时发现,请求过程的 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://stackoverflow.com/questions/55493745/is-it-possible-to-configure-httpclient-not-to-save-cookies

更多:

https://www.cnblogs.com/edison0621/p/11224890.html

https://www.cnblogs.com/edison0621/p/11261373.html

https://www.cnblogs.com/edison0621/p/11298882.html

相关文章:

  • 2021-08-13
  • 2021-10-01
  • 2021-07-06
  • 2022-02-25
  • 2022-03-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-11-17
  • 2021-08-06
  • 2022-12-23
  • 2021-06-09
相关资源
相似解决方案