C
C#3w ago
Mango

how to set HttpClientHandler when registering typed HttpClient?

title. is it possible to register an HttpClientHandler to a typed HttpClient?
4 Replies
Mango
MangoOP3w ago
given the below registration
builder.Services.AddHttpClient<ICatalogService, CatalogService>(client =>
{
client.BaseAddress = new Uri(builder.Configuration["BaseUrl"]);
});
builder.Services.AddHttpClient<ICatalogService, CatalogService>(client =>
{
client.BaseAddress = new Uri(builder.Configuration["BaseUrl"]);
});
is it possible? i see no property or method that will allow this
Sehra
Sehra3w ago
.AddHttpClient<ICatalogService, CatalogService>().AddHttpMessageHandler<MyHandler>() there is also a Func<IServiceProvider, DelegatingHandler> overload if you need access to that
FusedQyou
FusedQyou3w ago
Oh right I forgot to mention yesterday that the HTTPClient returns a builder by itself You should probably specify it from there
Mango
MangoOP3w ago
I just found that ClientHandler is MessageHandler

Did you find this page helpful?