有没有办法向 IHttpClientFactory 创建的所有客户端添加处理程序?我知道您可以对指定的客户端执行以下操作:
services.AddHttpClient("named", c =>
{
c.BaseAddress = new Uri("TODO");
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
c.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue
{
NoCache = true,
NoStore = true,
MaxAge = new TimeSpan(0),
MustRevalidate = true
};
}).ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
AllowAutoRedirect = false,
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip
});
但我不想使用命名客户端我只想向通过以下方式返回给我的所有客户端添加一个处理程序:
clientFactory.CreateClient();