我正在使用ASP.NET Core 2.2,其中使用了来自非安全门户的安全API(例如https://google.com)。 但是我在请求API时遇到错误:
System.Net.Http.HttpRequestException:无法建立SSL连接,请参阅内部异常。
我已经尝试使用AndroidX
,ServerCertificateCustomValidationCallback
,ServerCertificateCustomValidationCallback
等,但是没有用。
当我使用ServicePointManager.SecurityProtocol
时,我遇到了错误:
System.NotSupportedException:不支持所请求的安全协议”
我已经尝试过的示例代码::
1。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
2。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12 |
SecurityProtocolType.Ssl3;
3。
using (var httpClientHandler = new HttpClientHandler())
{
httpClientHandler.ServerCertificateCustomValidationCallback =
(message, cert, chain, errors) => { return true; };
using (var client = new HttpClient(httpClientHandler))
{ // somecode }
}