忽略通过IHttpClientFactory的SSL连接错误 [英] Ignore SSL connection errors via IHttpClientFactory
本文介绍了忽略通过IHttpClientFactory的SSL连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在从asp.net core 2.2项目连接到https网站(例如
I have a problem with a connect from my asp.net core 2.2 project to an https site like there. I use IHttpClientFactory to create typed HttpClient in Startup.cs
services.AddHttpClient<ICustomService, MyCustomService>();
我不明白,如何在不像这样手动创建HttpClient的情况下忽略SSL连接问题
And I don't understand, how can I ignore SSL connection problems without creating HttpClient manually like this
using (var customHandler = new HttpClientHandler())
{
customHandler.ServerCertificateCustomValidationCallback = (m, c, ch, e) => { return true; };
using (var customClient = new HttpClient(customHandler)
{
// my code
}
}
推荐答案
使用ConfigureHttpMessageHandlerBuilder
:
services.AddHttpClient<ICustomService, MyCustomService>()
.ConfigureHttpMessageHandlerBuilder(builder =>
{
builder.PrimaryHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (m, c, ch, e) => true
};
});
这篇关于忽略通过IHttpClientFactory的SSL连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文