HttpClientBuilderExtensions.UseSocketsHttpHandler Method

Definition

Overloads

UseSocketsHttpHandler(IHttpClientBuilder, Action<ISocketsHttpHandlerBuilder>)

Adds or updates SocketsHttpHandler as a primary handler for a named HttpClient and configures it using ISocketsHttpHandlerBuilder.

UseSocketsHttpHandler(IHttpClientBuilder, Action<SocketsHttpHandler,IServiceProvider>)

Adds or updates SocketsHttpHandler as a primary handler for a named HttpClient. If provided, also adds a delegate that will be used to configure the primary SocketsHttpHandler.

UseSocketsHttpHandler(IHttpClientBuilder, Action<ISocketsHttpHandlerBuilder>)

Source:
HttpClientBuilderExtensions.cs
Source:
HttpClientBuilderExtensions.cs
Source:
HttpClientBuilderExtensions.cs

Adds or updates SocketsHttpHandler as a primary handler for a named HttpClient and configures it using ISocketsHttpHandlerBuilder.

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder UseSocketsHttpHandler(this Microsoft.Extensions.DependencyInjection.IHttpClientBuilder builder, Action<Microsoft.Extensions.DependencyInjection.ISocketsHttpHandlerBuilder> configureBuilder);

Parameters

configureBuilder
Action<ISocketsHttpHandlerBuilder>

Delegate that is used to set up the configuration of the primary SocketsHttpHandler on ISocketsHttpHandlerBuilder that will later be applied on the primary handler during its creation.

Returns

An IHttpClientBuilder that can be used to configure the client.

Attributes

Remarks

If a primary handler was already set to be SocketsHttpHandler by previously calling, for example, ConfigurePrimaryHttpMessageHandler(IHttpClientBuilder, Func<HttpMessageHandler>) or UseSocketsHttpHandler(IHttpClientBuilder, Action<ISocketsHttpHandlerBuilder>), then the configuration set on ISocketsHttpHandlerBuilder will be applied to the existing instance. Otherwise, a new instance of SocketsHttpHandler will be created.

Applies to

.NET 9 (package-provided) and .NET 8 (package-provided)
Product Versions
.NET 8 (package-provided), 9 (package-provided)

UseSocketsHttpHandler(IHttpClientBuilder, Action<SocketsHttpHandler,IServiceProvider>)

Source:
HttpClientBuilderExtensions.cs
Source:
HttpClientBuilderExtensions.cs
Source:
HttpClientBuilderExtensions.cs

Adds or updates SocketsHttpHandler as a primary handler for a named HttpClient. If provided, also adds a delegate that will be used to configure the primary SocketsHttpHandler.

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder UseSocketsHttpHandler(this Microsoft.Extensions.DependencyInjection.IHttpClientBuilder builder, Action<System.Net.Http.SocketsHttpHandler,IServiceProvider>? configureHandler = default);

Parameters

configureHandler
Action<SocketsHttpHandler,IServiceProvider>

Optional delegate that is used to configure the primary SocketsHttpHandler.

Returns

An IHttpClientBuilder that can be used to configure the client.

Attributes

Remarks

If a primary handler was already set to be SocketsHttpHandler by previously calling, for example, ConfigurePrimaryHttpMessageHandler(IHttpClientBuilder, Func<HttpMessageHandler>) or UseSocketsHttpHandler(IHttpClientBuilder, Action<ISocketsHttpHandlerBuilder>), then the passed configureHandler delegate will be applied to the existing instance. Otherwise, a new instance of SocketsHttpHandler will be created.

Applies to

.NET 9 (package-provided) and .NET 8 (package-provided)
Product Versions
.NET 8 (package-provided), 9 (package-provided)