c# - SignalR 无法建立 SSL 连接

标签 c# asp.net xamarin.forms signalr

我使用 SignalR 在我的 ASP.NET 服务器和 Xamarin.Forms 客户端之间进行通信。但是,当我使用 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();

关于c# - SignalR 无法建立 SSL 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61905509/

相关文章:

php - 如何加速mysql以容纳数千行

c# - GetProperty ("pname") 返回 null

c# - SOAP 扩展实现

xamarin - 如何在 Xamarin 中创建 ResourceDictionary?

c# - 制作一组图片框,每个都有不同的图像

c# - 有没有办法在不抛出异常的情况下等待 TPL 任务?

ios - Xamarin.iOS statusBar BackgroundColor不会更改

c# - 在运行时更改 xamarin.forms 颜色

c# - 如何在 xamarin.mac 中绘制矩形

c# - 将 RSA 私钥存储在文件中