How to set connection timeout for Refit? The request may take for example 1 minute but I want to set timeout until the connection is established(30 secs max).
Asked
Active
Viewed 106 times
1 Answers
0
You can use the HttpClient.Timeout property to set the timeout for the entire request. This includes the time taken to establish the connection and receive the response. You can set the HttpClient.Timeout property to a TimeSpan value that represents the maximum time allowed for the request to complete.
Here's an example of how you can set the HttpClient.Timeout property using a TimeSpan value of 30 seconds:
var httpClient = new HttpClient();
// Set the HttpClient.Timeout property to 30 seconds
httpClient.Timeout = TimeSpan.FromSeconds(30);
var api = RestService.For<IMyApi>(httpClient);

Murad
- 52
- 5
-
Imagine you're downloading file with 30s timeout. – NightCity10932 Mar 29 '23 at 08:53