Microsoft.Extensions.Http 9.0.0-preview.5.24306.7

About

Microsoft.Extensions.Http package provides AddHttpClient extension methods for IServiceCollection, IHttpClientFactory interface and its default implementation. This provides the ability to set up named HttpClient configurations in a DI container and later retrieve them via an injected IHttpClientFactory instance.

Key Features

  • The package allows to fluently set up multiple HttpClient configurations for applications that use DI via AddHttpClient extension method.
  • HttpClientFactory caches HttpMessageHandler instances per configuration name, which allows to reuse resources between HttpClient instances to avoid port exhaustion.
  • HttpClientFactory manages lifetime of HttpMessageHandler instances and recycles connections to track DNS changes.

How to Use

Note that lifetime management of HttpClient instances created by HttpClientFactory is completely different from instances created manually. The strategies are to use either short-lived clients created by HttpClientFactory or long-lived clients with PooledConnectionLifetime set up. For more information, see the HttpClient lifetime management section in the conceptual docs and Guidelines for using HTTP clients.

Configuring HttpClient

builder.Services.AddHttpClient("foo"); // adding an HttpClient named "foo" with a default configuration

builder.Services.AddHttpClient("example", c => c.BaseAddress = new Uri("https://www.example.com")) // configuring HttpClient itself
    .AddHttpMessageHandler<MyAuthHandler>() // adding additional delegating handlers to form a message handler chain
    .ConfigurePrimaryHttpMessageHandler(b => new HttpClientHandler() { AllowAutoRedirect = false }) // configuring primary handler
    .SetHandlerLifetime(TimeSpan.FromMinutes(30)); // changing the handler recycling interval

Using the configured HttpClient

public class MyService
{
    public MyService(IHttpClientFactory httpClientFactory)
    {
        _httpClientFactory = httpClientFactory; // injecting the factory
    }

    private Task<string> GetExampleAsync(Uri uri, CancellationToken ct)
    {
        HttpClient exampleClient = _httpClientFactory.CreateClient("example"); // creating the client for the specified name
        return exampleClient.GetStringAsync(uri, ct); // using the client
    }
}

Main Types

The main types provided by this library are:

  • IHttpClientFactory
  • IHttpMessageHandlerFactory
  • HttpClientFactoryServiceCollectionExtensions

Additional Documentation

Feedback & Contributing

Microsoft.Extensions.Http is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Showing the top 20 packages that depend on Microsoft.Extensions.Http.

Packages Downloads
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
63
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
60
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
57
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
56
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/509f6badec2f3162f0e50330cd9107e5624b379b
56
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/aee5e4080331553ea9dfb7fb388b6d72f715bf6a
55
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/cf2c5c9c6dca430b97aa96429b84d0da07eb77f1
55
Microsoft.AspNetCore.All
Provides a default set of APIs for building an ASP.NET Core application, and also includes API for third-party integrations with ASP.NET Core. This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.
55
AspNetCore.HealthChecks.Uris
HealthChecks.Uris is a simple health check package for Uri groups.
53
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/f6897a5bb7ca767df8eb465bf15b193c878fffbf
53
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/55738ff96b832439076e25584cfe0eb3bace9b01
53
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/68bb6fb08f8f85bb3cf08953a0d2f4a254eaccff
53
Microsoft.AspNetCore.ApiAuthorization.IdentityServer
ASP.NET Core API Authorization package powered by Identity Server. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/70048beee894074e9718206a0017d9b080ee66ff
53

https://go.microsoft.com/fwlink/?LinkID=799421

.NET Framework 4.6.2

.NET Standard 2.0

.NET 9.0

.NET 8.0

Version Downloads Last updated
10.0.0-preview.5.25277.114 4 06/14/2025
10.0.0-preview.4.25258.110 10 05/13/2025
10.0.0-preview.3.25171.5 16 04/12/2025
10.0.0-preview.2.25163.2 16 03/23/2025
10.0.0-preview.1.25080.5 20 02/25/2025
9.0.6 3 06/12/2025
9.0.5 7 05/15/2025
9.0.4 18 04/11/2025
9.0.3 18 03/12/2025
9.0.2 19 02/14/2025
9.0.1 26 01/17/2025
9.0.0 36 11/13/2024
9.0.0-rc.2.24473.5 27 10/16/2024
9.0.0-rc.1.24431.7 26 09/11/2024
9.0.0-preview.7.24405.7 30 08/15/2024
9.0.0-preview.6.24327.7 38 07/11/2024
9.0.0-preview.5.24306.7 34 06/12/2024
9.0.0-preview.4.24266.19 33 05/23/2024
9.0.0-preview.3.24172.9 30 04/20/2024
9.0.0-preview.2.24128.5 36 03/19/2024
9.0.0-preview.1.24080.9 41 03/05/2024
8.0.1 34 10/17/2024
8.0.0 46 11/15/2023
8.0.0-rc.2.23479.6 35 10/19/2023
8.0.0-rc.1.23419.4 44 09/13/2023
8.0.0-preview.7.23375.6 36 08/24/2023
8.0.0-preview.6.23329.7 44 07/23/2023
8.0.0-preview.5.23280.8 34 07/05/2023
8.0.0-preview.4.23259.5 38 05/20/2023
8.0.0-preview.3.23174.8 35 05/13/2023
8.0.0-preview.2.23128.3 34 07/07/2023
8.0.0-preview.1.23110.8 40 02/25/2023
7.0.0 52 12/07/2022
7.0.0-rc.2.22472.3 39 07/03/2023
7.0.0-rc.1.22426.10 43 07/05/2023
7.0.0-preview.7.22375.6 40 11/05/2022
7.0.0-preview.6.22324.4 40 07/08/2023
7.0.0-preview.5.22301.12 36 05/06/2023
7.0.0-preview.4.22229.4 38 09/24/2022
7.0.0-preview.3.22175.4 37 06/29/2023
7.0.0-preview.2.22152.2 43 07/05/2023
7.0.0-preview.1.22076.8 45 09/26/2022
6.0.2-mauipre.1.22102.15 40 10/22/2022
6.0.2-mauipre.1.22054.8 40 11/18/2022
6.0.1 28 11/18/2024
6.0.0 49 07/28/2022
6.0.0-rc.2.21480.5 42 05/27/2023
6.0.0-rc.1.21451.13 36 07/04/2023
6.0.0-preview.7.21377.19 45 10/02/2022
6.0.0-preview.6.21352.12 32 07/05/2023
6.0.0-preview.5.21301.5 43 05/04/2023
6.0.0-preview.4.21253.7 39 04/25/2023
6.0.0-preview.3.21201.4 38 11/15/2022
6.0.0-preview.2.21154.6 44 11/16/2022
6.0.0-preview.1.21102.12 33 05/03/2023
5.0.0 45 07/03/2022
5.0.0-rc.2.20475.5 36 05/07/2023
5.0.0-rc.1.20451.14 35 05/12/2023
5.0.0-preview.8.20407.11 35 07/18/2023
5.0.0-preview.7.20364.11 45 07/03/2023
5.0.0-preview.6.20305.6 31 07/03/2023
5.0.0-preview.5.20278.1 40 02/20/2023
5.0.0-preview.4.20251.6 41 05/23/2023
5.0.0-preview.3.20215.2 35 05/19/2023
5.0.0-preview.2.20160.3 42 10/11/2022
5.0.0-preview.1.20120.4 44 01/18/2023
3.1.32 42 05/02/2023
3.1.31 45 01/17/2023
3.1.30 37 02/25/2023
3.1.29 47 12/19/2022
3.1.28 50 09/30/2022
3.1.27 48 10/11/2022
3.1.26 44 05/12/2023
3.1.25 41 10/03/2022
3.1.24 46 11/16/2022
3.1.23 45 10/03/2022
3.1.22 38 09/29/2022
3.1.21 42 10/08/2022
3.1.20 43 11/30/2022
3.1.19 38 09/29/2022
3.1.18 37 09/23/2022
3.1.17 45 09/26/2022
3.1.16 51 09/27/2022
3.1.15 42 10/08/2022
3.1.14 42 12/21/2022
3.1.13 39 05/16/2023
3.1.12 37 09/26/2022
3.1.11 39 10/07/2022
3.1.10 44 09/28/2022
3.1.9 41 09/25/2022
3.1.8 50 09/23/2022
3.1.7 52 11/19/2022
3.1.6 44 11/06/2022
3.1.5 50 11/30/2022
3.1.4 44 04/18/2023
3.1.3 53 09/23/2022
3.1.2 39 09/28/2022
3.1.1 48 09/22/2022
3.1.0 44 11/05/2022
3.1.0-preview3.19553.2 39 10/23/2022
3.1.0-preview2.19525.4 41 12/04/2022
3.1.0-preview1.19506.1 36 05/10/2023
3.0.3 44 10/29/2022
3.0.2 49 09/22/2022
3.0.1 46 11/19/2022
3.0.0 52 09/29/2022
3.0.0-rc1.19456.10 31 07/13/2023
3.0.0-preview9.19423.4 33 07/08/2023
3.0.0-preview8.19405.4 39 05/03/2023
3.0.0-preview7.19362.4 39 07/05/2023
3.0.0-preview6.19304.6 40 11/08/2022
3.0.0-preview5.19227.9 42 11/28/2022
3.0.0-preview4.19216.2 35 07/08/2023
3.0.0-preview3.19153.1 41 07/04/2023
3.0.0-preview.19074.2 35 07/03/2023
3.0.0-preview.18572.1 39 03/18/2023
2.2.0 54 09/23/2022
2.2.0-preview3-35497 43 10/10/2022
2.2.0-preview2-35157 41 05/24/2023
2.2.0-preview1-35029 36 10/26/2022
2.1.1 46 06/07/2022
2.1.0 47 09/30/2022
2.1.0-rc1-final 43 05/20/2023
2.1.0-preview2-final 41 09/23/2022
2.1.0-preview1-final 41 11/24/2022