The request was aborted: Could not create SSL/TLS secure channel

一、背景:

公司底层服务CDN从Akamai迁移到阿里云之后, 使用该服务的一个应用报错如下:

System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)

二、排查步骤:

  1、使用Postman测试接口没有问题.

  2、本地调试发现HttpClient不能获取返回结果, 两种情况, 一种请求压根没发出去, 第二种是在网络层面被拒绝了.

  3、从报错信息来看, 个人感觉是第二种, 看上去像是网络协议的问题.

三、解决办法:

定位了问题就好办了, 网上一查便知, 添加了如下代码:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
        | SecurityProtocolType.Tls11
        | SecurityProtocolType.Tls12
        | SecurityProtocolType.Ssl3;
posted @ 2019-08-22 10:37  齐建伟  阅读(3998)  评论(2编辑  收藏  举报