C# 无法建立SSL连接的信号器

C# 无法建立SSL连接的信号器,c#,asp.net,xamarin.forms,signalr,C#,Asp.net,Xamarin.forms,Signalr,我正在使用SignalR在ASP.NET服务器和Xamarin.Forms客户端之间进行通信。但是,当我使用https时,HubConnection在尝试.StartAsync()时引发此异常:System.Net.Http.HttpRequestException:“无法建立SSL连接,请参阅内部异常。 然而,当我改用http时,一切正常。 请帮帮我! 提前谢谢你 因此,我通过将Xamarin.Forms shared project.NETStandard版本升级到2.1并通过以下方式重写H

我正在使用SignalR在ASP.NET服务器和Xamarin.Forms客户端之间进行通信。但是,当我使用https时,HubConnection在尝试.StartAsync()时引发此异常:
System.Net.Http.HttpRequestException:“无法建立SSL连接,请参阅内部异常。
然而,当我改用http时,一切正常。 请帮帮我!
提前谢谢你

因此,我通过将Xamarin.Forms shared project.NETStandard版本升级到2.1并通过以下方式重写HubConnectionBuilder解决了这个问题:

hubConnection = new HubConnectionBuilder().WithUrl(Properties.Resources.ServerIPAddress + "/test",
                options =>
                {
                    options.WebSocketConfiguration = conf =>
                    {
                        conf.RemoteCertificateValidationCallback = (message, cert, chain, errors) => { return true; };
                    };
                    options.HttpMessageHandlerFactory = factory => new HttpClientHandler
                    {
                        ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
                    };
                    options.AccessTokenProvider = () => Task.FromResult(Token);
                }).Build();

请记住将您的回答标记为答案,找到这个答案对其他人很有帮助,谢谢。
 hubConnection = new HubConnectionBuilder()
     .WithUrl($"your host/chatHub", (opts) =>
     {
         opts.HttpMessageHandlerFactory = (message) =>
         {
             if (message is HttpClientHandler clientHandler)
                 // bypass SSL certificate
                 clientHandler.ServerCertificateCustomValidationCallback +=
                     (sender, certificate, chain, sslPolicyErrors) => { return true; };
             return message;
         };
     }).Build();