HttpClientBuilderExtensions.UseSocketsHttpHandler 方法

定义

重载

UseSocketsHttpHandler(IHttpClientBuilder, Action<ISocketsHttpHandlerBuilder>)

添加或更新 SocketsHttpHandler 为命名 HttpClient 的 的主处理程序,并使用 ISocketsHttpHandlerBuilder对其进行配置。

UseSocketsHttpHandler(IHttpClientBuilder, Action<SocketsHttpHandler,IServiceProvider>)

添加或更新 SocketsHttpHandler 为命名 HttpClient的主处理程序。 如果提供,还会添加将用于配置主 SocketsHttpHandler的委托。

UseSocketsHttpHandler(IHttpClientBuilder, Action<ISocketsHttpHandlerBuilder>)

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

添加或更新 SocketsHttpHandler 为命名 HttpClient 的 的主处理程序,并使用 ISocketsHttpHandlerBuilder对其进行配置。

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IHttpClientBuilder ^ UseSocketsHttpHandler(Microsoft::Extensions::DependencyInjection::IHttpClientBuilder ^ builder, Action<Microsoft::Extensions::DependencyInjection::ISocketsHttpHandlerBuilder ^> ^ configureBuilder);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder UseSocketsHttpHandler (this Microsoft.Extensions.DependencyInjection.IHttpClientBuilder builder, Action<Microsoft.Extensions.DependencyInjection.ISocketsHttpHandlerBuilder> configureBuilder);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member UseSocketsHttpHandler : Microsoft.Extensions.DependencyInjection.IHttpClientBuilder * Action<Microsoft.Extensions.DependencyInjection.ISocketsHttpHandlerBuilder> -> Microsoft.Extensions.DependencyInjection.IHttpClientBuilder
<Extension()>
Public Function UseSocketsHttpHandler (builder As IHttpClientBuilder, configureBuilder As Action(Of ISocketsHttpHandlerBuilder)) As IHttpClientBuilder

参数

configureBuilder
Action<ISocketsHttpHandlerBuilder>

委托,用于设置主SocketsHttpHandlerISocketsHttpHandlerBuilder处理程序的配置,稍后将在主处理程序创建期间应用于主处理程序。

返回

可用于配置客户端的 IHttpClientBuilder

属性

注解

如果之前通过调用 (例如 ConfigurePrimaryHttpMessageHandler(IHttpClientBuilder, Func<HttpMessageHandler>)UseSocketsHttpHandler(IHttpClientBuilder, Action<ISocketsHttpHandlerBuilder>)) 将SocketsHttpHandler主处理程序设置为 ,则上的ISocketsHttpHandlerBuilder配置设置将应用于现有实例。 否则,将创建 的新 SocketsHttpHandler 实例。

适用于

UseSocketsHttpHandler(IHttpClientBuilder, Action<SocketsHttpHandler,IServiceProvider>)

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

添加或更新 SocketsHttpHandler 为命名 HttpClient的主处理程序。 如果提供,还会添加将用于配置主 SocketsHttpHandler的委托。

[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);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member UseSocketsHttpHandler : Microsoft.Extensions.DependencyInjection.IHttpClientBuilder * Action<System.Net.Http.SocketsHttpHandler, IServiceProvider> -> Microsoft.Extensions.DependencyInjection.IHttpClientBuilder
<Extension()>
Public Function UseSocketsHttpHandler (builder As IHttpClientBuilder, Optional configureHandler As Action(Of SocketsHttpHandler, IServiceProvider) = Nothing) As IHttpClientBuilder

参数

configureHandler
Action<SocketsHttpHandler,IServiceProvider>

用于配置主 SocketsHttpHandler的可选委托。

返回

可用于配置客户端的 IHttpClientBuilder

属性

注解

如果之前通过调用 (例如ConfigurePrimaryHttpMessageHandler(IHttpClientBuilder, Func<HttpMessageHandler>)) 或 UseSocketsHttpHandler(IHttpClientBuilder, Action<ISocketsHttpHandlerBuilder>)将主处理程序设置为 SocketsHttpHandler ,则传递的configureHandler委托将应用于现有实例。 否则,将创建 的新 SocketsHttpHandler 实例。

适用于