简体   繁体   中英

HTTPWebRequest Could not create SSL/TLS secure channel



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.

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; 

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.

Try to create self signed certificate from your server and add it to your client machine.

Create self signed certificate (Server side)

Import self signed certificate (Client side)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM