共用方式為


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`1configurePolicy 已預先設定錯誤,可處理下列類別中的錯誤:

  • 網路失敗 (為 HttpRequestException)
  • HTTP 5XX 狀態代碼 (伺服器錯誤)
  • HTTP 408 狀態代碼 (要求逾時)

configurePolicy 建立的原則將會依具名客戶端無限期快取。 原則通常設計為做為單一專案,並可在適當時共用。 若要跨多個具名用戶端共享原則,請先建立原則,然後視需要將它傳遞給多個呼叫 AddPolicyHandler(IHttpClientBuilder, IAsyncPolicy<HttpResponseMessage>)

適用於