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)); } }
标签:webapi,core,GetSection,chain,AddHttpClient,services,handler,var From: https://www.cnblogs.com/hofmann/p/17816807.html