Replies: 1 comment
-
You can use the public void ConfigureServices(IServiceCollection services)
{
// Register default HttpClient
services.AddHttpClient("default");
// Register custom HttpClient with custom handler
services.AddHttpClient("customClient");
} Then in your code use the custom instance: public class YourService
{
private readonly HttpClient _defaultClient;
private readonly HttpClient _customClient;
public YourService(IHttpClientFactory httpClientFactory)
{
_defaultClient = httpClientFactory.CreateClient("default");
_customClient = httpClientFactory.CreateClient("customClient");
}
public async Task UseClientsAsync()
{
var responseDefault = await _defaultClient.GetAsync("https://something");
var responseCustom = await _customClient.GetAsync("https://something");
// ....
}
} Anyway, if you want to override the default: var customHandler = new SocketsHttpHandler
{
// Custom settings here
};
// Create a single HttpClient instance with the custom handler
var httpClient = new HttpClient(customHandler);
var response = await httpClient.GetAsync("https://something"); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, i have a 2 type HttpClient.
1 => Default
2 => With custom SocketsHttpHandler
i want to add support for my custom SocketsHttpHandler.
How can i add that?
Can i override default?
Can i add support without override default one (supporting both in same time)? And how can i do that? With using another port, prefix route... etc?
How can i get custom data which is getted from SocketsHttpHandler?
Beta Was this translation helpful? Give feedback.
All reactions