PollyHttpClientBuilderExtensions.AddTransientHttpErrorPolicy 方法

定义

添加 PolicyHttpMessageHandler,它将使用通过执行提供的配置委托创建的 Policy 将请求执行涵盖在内。 策略生成器将预先配置为针对失败的请求(带有指示暂时性故障的条件)的策略的触发器应用程序。

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IHttpClientBuilder ^ AddTransientHttpErrorPolicy(Microsoft::Extensions::DependencyInjection::IHttpClientBuilder ^ builder, Func<Polly::PolicyBuilder<System::Net::Http::HttpResponseMessage ^> ^, Polly::IAsyncPolicy<System::Net::Http::HttpResponseMessage ^> ^> ^ configurePolicy);
public static Microsoft.Extensions.DependencyInjection.IHttpClientBuilder AddTransientHttpErrorPolicy (this Microsoft.Extensions.DependencyInjection.IHttpClientBuilder builder, Func<Polly.PolicyBuilder<System.Net.Http.HttpResponseMessage>,Polly.IAsyncPolicy<System.Net.Http.HttpResponseMessage>> configurePolicy);
static member AddTransientHttpErrorPolicy : Microsoft.Extensions.DependencyInjection.IHttpClientBuilder * Func<Polly.PolicyBuilder<System.Net.Http.HttpResponseMessage>, Polly.IAsyncPolicy<System.Net.Http.HttpResponseMessage>> -> Microsoft.Extensions.DependencyInjection.IHttpClientBuilder
<Extension()>
Public Function AddTransientHttpErrorPolicy (builder As IHttpClientBuilder, configurePolicy As Func(Of PolicyBuilder(Of HttpResponseMessage), IAsyncPolicy(Of HttpResponseMessage))) As IHttpClientBuilder

参数

返回

可用于配置客户端的 IHttpClientBuilder

注解

有关配置策略的指导,请参阅 上的 PolicyHttpMessageHandler 说明。

PolicyBuilder`1提供给 configurePolicy 的 已预配置错误,用于处理以下类别中的错误:

  • 网络故障 (为 HttpRequestException)
  • HTTP 5XX 状态代码 (服务器错误)
  • HTTP 408 状态代码 (请求超时)

创建的 configurePolicy 策略将按命名客户端无限期缓存。 策略通常设计为作为单一实例,并可在适当时共享。 若要在多个命名客户端之间共享策略,请先创建该策略,然后根据需要将其传递给多个调用 AddPolicyHandler(IHttpClientBuilder, IAsyncPolicy<HttpResponseMessage>)

适用于