0

I have a very strange issue and it costs me a day now.

The error exception.

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)

at System.Net.HttpWebRequest.GetRequestStream()

at RestSharp.Http.WriteRequestBody(HttpWebRequest webRequest)

at RestSharp.Http.PostPutInternal(String method)

at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse)

My code is working on the TEST-environment, but not on my local environment. The code has worked in the past and nothing has changed. I reproduced the REST-call on my local machine in SoapUi and there it's working. I imported the SSL-certificate etc. My local machine is runnning Windows 7 and the TEST-environment Windows Server 2008. Both environments are running .NET Framework 4.5.

I searched the internet for a solution and I've found a lot, for example The request was aborted: Could not create SSL/TLS secure channel http://robertgreiner.com/2013/03/could-not-establish-trust-relationship-for-the-ssl-tls-secure-channel/

I tried the possible solutions, but I did not solve the issue. Does anyone know the solution?

Thanks a lot, Jordy

Community
  • 1
  • 1
Jordy
  • 661
  • 7
  • 26

2 Answers2

0

It seems that there's a problem during handshake of your Test-environment and another server.

Try this before call the server:

ServicePointManager.ServerCertificateValidationCallback =
                        (s, certificate, chain, sslPolicyErrors) => true;

PS: The line above will disable SSL validation.

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • I WILL NOT ALLOW YOU TO GIVE SUCH AN ANSWER WITHOUT YOU INCLUDING THE SECURITY IMPLICATIONS THAT RUNNING THIS CODE HAS. – Aron Aug 31 '15 at 16:41
  • @Aron where is your answer? – Thiago Custodio Aug 31 '15 at 17:11
  • I agree with the answer. Just not the fact that you have just told the OP to disable SSL without telling him what that means. – Aron Aug 31 '15 at 17:12
  • no, as I said...it seems that the problem he is facing is related to a handshake between server and test environment. To confirm that, he could use the code I've posted. Not it should be the final answer and used in production. – Thiago Custodio Aug 31 '15 at 17:25
  • That should be a comment then. You made it look like an answer. Which is super dangerous. – Aron Aug 31 '15 at 17:26
  • 1
    Thank you for understanding me, the line of code Thiago is suggesting is inside my code for months now (see also the links in my question). The code has also worked locally. Nothing has changed in the code. I heared that the SSL certificate has changed with a wildcard. I have updated the certificate inside the Windows certificate manager. Maybe that's something. – Jordy Sep 01 '15 at 07:18
0

The SSL-certificate had a too low/bad encryption key, so Windows was not accepting it anymore after several Windows updates. The solution was to renew the SSL-certificate with an higher encryption key.

Jordy
  • 661
  • 7
  • 26