我使用 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/