我的asp.net core 2.2项目与https站点(如there)之间的连接出现问题。我使用IHttpClientFactory在Startup.cs中创建类型化的HttpClient
services.AddHttpClient<ICustomService, MyCustomService>();
我不明白,如何在不像这样手动创建HttpClient的情况下忽略SSL连接问题
using (var customHandler = new HttpClientHandler())
{
customHandler.ServerCertificateCustomValidationCallback = (m, c, ch, e) => { return true; };
using (var customClient = new HttpClient(customHandler)
{
// my code
}
}
答案 0 :(得分:4)
使用ConfigureHttpMessageHandlerBuilder
:
services.AddHttpClient<ICustomService, MyCustomService>()
.ConfigureHttpMessageHandlerBuilder(builder =>
{
builder.PrimaryHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (m, c, ch, e) => true
};
});