2



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.

Magellan
  • 71
  • 1
  • 2
  • 11

3 Answers3

4

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; 
Nirman
  • 6,715
  • 19
  • 72
  • 139
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.

Magellan
  • 71
  • 1
  • 2
  • 11
0

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)

Leon Barkan
  • 2,676
  • 2
  • 19
  • 43