static public class CreditScoreServiceExtension
{
static public void AddCreditScoreQueryServiceHttpClient(this IServiceCollection services, IConfiguration config)
{
services.AddSingleton<ICreditScoreQueryService, CreditScoreQueryService>();
//var serviceUrl = config.GetSection("AppSettings").GetSection("FC").GetSection("CreditScore")["ServiceUrl"];
//var baseUri = new Uri(serviceUrl);
services.AddHttpClient<ICreditScoreQueryService, CreditScoreQueryService>(client => { })
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler();
//if (baseUri.Scheme.ToLower() == "https")
//{
// handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
//}
handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;
return handler;
}).SetHandlerLifetime(TimeSpan.FromMinutes(5));
}
}
asp.net core IHttpClientFactroy 进行SSL(https)请求时注入ConfigurePrimaryHttpMessageHandler解决https请求错误: