How to use HttpClientHandler with HttpClientFactory in .NET Core

前端 未结 2 1268
北荒
北荒 2021-01-03 23:13

I want to use the HttpClientFactory that is available in .NET Core 2.1 but I also want to use the HttpClientHandler to utilize the AutomaticD

2条回答
  •  梦毁少年i
    2021-01-04 00:14

    Actually I'm not using automatic decompression but the way to achieve this is to properly register http client

    services.AddHttpClient()
       .ConfigureHttpMessageHandlerBuilder((c) =>
         new HttpClientHandler()
         {
            AutomaticDecompression = System.Net.DecompressionMethods.GZip
         }
       )
       .AddHttpMessageHandler((s) => s.GetService())
    

提交回复
热议问题