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

后端 未结 30 2575
遇见更好的自我
遇见更好的自我 2020-11-22 01:21

We are unable to connect to an HTTPS server using WebRequest because of this error message:

The request was aborted: Could not create SSL/TLS secur

30条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 01:55

    Make sure the ServicePointManager settings are made before the HttpWebRequest is created, else it will not work.

    Works:

    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
           | SecurityProtocolType.Tls11
           | SecurityProtocolType.Tls12
           | SecurityProtocolType.Ssl3;
    
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://google.com/api/")
    

    Fails:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://google.com/api/")
    
    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
           | SecurityProtocolType.Tls11
           | SecurityProtocolType.Tls12
           | SecurityProtocolType.Ssl3;
    

提交回复
热议问题