• 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;
  • 相关阅读:
    Redis
    Redis入门
    C#编程--语句(分支语句)
    C#编程--运算符
    C#编程--输入和输出
    C#编程进制转换
    C#语言课程11月10日
    C#语言课程11月9日
    C#语言课程11月7日
    C#语言课程11月6日
  • 原文地址:https://www.cnblogs.com/jerryqi/p/11392913.html
Copyright © 2020-2023  润新知