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

后端 未结 30 1776
遇见更好的自我
遇见更好的自我 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:52

    As you can tell there are plenty of reasons this might happen. Thought I would add the cause I encountered ...

    If you set the value of WebRequest.Timeout to 0, this is the exception that is thrown. Below is the code I had... (Except instead of a hard-coded 0 for the timeout value, I had a parameter which was inadvertently set to 0).

    WebRequest webRequest = WebRequest.Create(@"https://myservice/path");
    webRequest.ContentType = "text/html";
    webRequest.Method = "POST";
    string body = "...";
    byte[] bytes = Encoding.ASCII.GetBytes(body);
    webRequest.ContentLength = bytes.Length;
    var os = webRequest.GetRequestStream();
    os.Write(bytes, 0, bytes.Length);
    os.Close();
    webRequest.Timeout = 0; //setting the timeout to 0 causes the request to fail
    WebResponse webResponse = webRequest.GetResponse(); //Exception thrown here ...
    

提交回复
热议问题