Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am able to call my service from postman but when i copy the code from code snippet which is provided by postman itself and trying to run from visual studio C# console application ( Framework 4.7.2) getting below exception.

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


Code is as below

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

            var client = new RestClient("https://XXX.XX.COM/token");
            var request = new RestRequest(Method.POST);
            request.AddHeader("Postman-Token", "XXXXX");
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("undefined", "{\r\n    \"client_id\":\"XXXX\",\r\n    \"userid\":\"XXXX\",\r\n    \"password\":\"XXXX\"\r\n}\r\n", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);


What I have tried:

I have tried by adding below code but still its giving me same error.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
           ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
Posted
Updated 4-Feb-21 17:56pm
Comments
Sandeep Mewara 29-Dec-20 13:12pm    
See if oyu have problem similar to this: [Solved] could not create SSL/TLS secure channel[^]

You are setting ServicePointManager.SecurityProtocol twice, try removing the line:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

You can also try setting this first:
ServicePointManager.Expect100Continue = true;

Otherwise try the steps here: cannot-connect-to-a-server-by-using-the-servicepointmanager-or-sslstre[^]

Btw. using the ServicePointManager Class[^] is not recommended anymore:
Quote:
We don't recommend that you use the ServicePointManager class for new development. Instead, use the System.Net.Http.HttpClient class.
 
Share this answer
 
v4
Comments
vishal_h 30-Dec-20 2:59am    
I tried same but getting same error.
We have resolved this issue as there was cipher mismatch between windows server 2012 R2 and Linux server while communication.
 
Share this answer
 
Comments
Harold N Bright 16-Jul-21 5:33am    
Hi vishal_h- how were you able to solve it? Even i came to the conclusion that the cypher difference is there, however i am not aware on how to solve it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900