繁体   English   中英

SignalR SSL 连接无法建立

[英]SignalR The SSL connection could not be established

我正在使用 SignalR 在我的 ASP.NET 服务器和 Xamarin.Z6450242531912981C6Z68 客户端之间进行通信。 但是,当我使用 https 时,HubConnection 在尝试时抛出此异常。StartAsync(): System.Net.Http.HttpRequestException: 'The SSL connection could not be established, see inner exception. 但是,当我改用 http 时,一切正常。 请帮我! 先感谢您!

因此,我通过将 Xamarin.Forms 共享项目 .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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM