Click here to Skip to main content
15,885,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am sending json request to Core and trying to fetch the response. but I am getting below exception
Request was aborted.Could not create SSL/TLS secure channel.


What I have tried:

Below is my code:
ServicePointManager.Expect100Continue = true;
                   ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                      | SecurityProtocolType.Tls11
                      | SecurityProtocolType.Tls12
                      | SecurityProtocolType.Ssl3;
                   request = (HttpWebRequest)WebRequest.Create(RequestURL);
                   System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                   request.Method = RequestMethod;
                   request.Accept = @"application/json";
                   request.ContentType = @"application/json";
                   Byte[] byteArray = encoding.GetBytes(jsonRequest);
                   request.ContentLength = byteArray.Length;

                   using (Stream stm = request.GetRequestStream())
                   {
                       stm.Write(byteArray, 0, byteArray.Length);
                   }
                   txtLog.Text += "Transact_Posting_Core()-Getting Request Stream Process Completed" + Environment.NewLine;
               }
               catch (Exception ex)
               {

                   return false;
               }




                   using (StreamReader responseReader = new StreamReader(request.GetResponse().GetResponseStream()))
                   {
                       jsonResponse = responseReader.ReadToEnd();
                       ResponseReceivedDate = DateTime.Now;
                   }


                   if (string.IsNullOrEmpty(jsonResponse))
                   {
                       txtLog.Text += "Transact_Posting_Core()-Response Fetched from Core as:" + jsonResponse + Environment.NewLine;

                       HttpWebResponse Response = (HttpWebResponse)request.GetResponse();
                       if (Response.StatusCode == HttpStatusCode.OK)
                       {
                           HTTP_StatusCode = "200";
                           ResponseStatus = "S";

                       }
Posted
Updated 30-Oct-22 23:52pm

1 solution

The server you're trying to connect to does not support any of the protocols you're trying to use (SSL3, TLS1.0, TLS1.1, TLS1.2). At a guess, it may only support TLS1.3, since earlier versions have security vulnerabilities.

You need to check which protocols the server has enabled, and make sure your client enables that protocol.

The recommended approach is to leave the protocol selection up to the operating system.
Transport Layer Security (TLS) best practices with the .NET Framework - .NET Framework | Microsoft Learn[^]
 
Share this answer
 

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



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