Просмотр исходного кода

Allow valid https requests in .NET Core

ServerCertificateValidationCallback on the ServicePointManager is not supported in .NET Core and outgoing https requests will fail if the certificate is not trusted.

This adds the equivalent functionality
Steve Hayles 5 лет назад
Родитель
Сommit
da9a59de1e
1 измененных файлов с 11 добавлено и 1 удалено
  1. 11 1
      Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs

+ 11 - 1
Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs

@@ -59,7 +59,17 @@ namespace Emby.Server.Implementations.HttpClientManager
 
             if (!_httpClients.TryGetValue(key, out var client))
             {
-                client = new HttpClient()
+                var httpClientHandler = new HttpClientHandler()
+                {
+                    ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
+                    {
+                        var success = errors == System.Net.Security.SslPolicyErrors.None;
+                        _logger.LogDebug("Validating certificate {Cert}. Success {1}", cert, success);
+                        return success;
+                    }
+                };
+
+                client = new HttpClient(httpClientHandler)
                 {
                     BaseAddress = new Uri(url)
                 };