HTTPWebRequest Could not create SSL/TLS secure channel

10,339

Solution 1

Two things that I was doing wrong.

  1. The Server wanted date in yyyy-MM-ddTHH:mm:ss, I was providing the date in yyyy-MM-ddTHH:mm:ss.ssss Format(DateTime.UtcNow.ToString("o")). This was the cause of Could not create SSL/TLS secure channel

  2. The server wanted the parameters in request body as well. I had passed the parameters only as query string. This was the cause of HTTP 404

In the process, I had asked a guy outside my team to help. He had asked me to see if there were any SSL related errors. To do this he asked me to add System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); and define AcceptAllCertifications, which was not the case. So to resolve the issue, I had to take care of the things mentioned above.

Solution 2

Which solution you have tried? It's worth trying the following if you haven't already - write following before you actually invoke the service:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; 
Share:
10,339
Magellan
Author by

Magellan

Updated on June 04, 2022

Comments

  • Magellan
    Magellan almost 2 years



    I am trying to call a Web API using HttpWebRequest(Console Application). To upload the file, I am using the code snippet provided by @Cristian Romanescu ont this question Upload files with HTTPWebrequest (multipart/form-data)

    If I set the req.ProtocolVersion as HttpVersion.Version10,I get Bad request when I try to do req.GetResponseStream().

    If i set the req.ProtocolVersion as HttpVersion.Version11,I get Could not create SSL/TLS secure channel. when i try to do req.GetResponseStream().

    If tried to post the data using POSTMAN, but even Postman says Could not get any response".

    If I try to hit the URL using IE-11 I get HTTP 404.[I know i am not posting the actual file], but Chrome displays the custom/appropriate error message.

    I tried the solutions already provided on stackoverflow, but unfortunately they do not solve my problem.

    Thankyou.

  • Joseph
    Joseph almost 7 years
    I think SSL3 is no longer considered secure. For more info stackoverflow.com/a/6584992/6190900
  • Nirman
    Nirman almost 7 years
    Thanks Joseph for making aware about SSL3. I have updated answer now.