Using .NET8, on a “HttpIOException: The response ended prematurely”, how can I add retries with exponential backoff?

  Kiến thức lập trình

developing a .Net8 application and currently having a need to perform http request retries when the connection ended prematurely (see ResponseEnded here)…

I wonder if I can use resilience mechanism with Polly and/or Microsoft.Extensions.Http.Resilience ?

Does the resilience retry mechanism will work by default on that exceptional case ?
Or it require custom policy or custom delegating handler to do so ?

Thank you

Program.cs

builder.Services.AddHttpClient()
   .AddResilienceHandler("my-pipeline", b => {
     b.AddRetry(new HttpRetryStrategyOptions()); // retry default policies
    });

New contributor

Jacques Boivin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT