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

Utu
Regular Visitor

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

Hi,

 

I have created sandbox api, the p12 cert was generated, jks file was imported, and the test is passed  in SOAPUI,  everything done.

 

But when I created a application to send test request, I always got a errror as  'The request was aborted: Could not create SSL/TLS secure channel.'

 

I have followed C# code from Visa in gitHub. 

 

Can I know how to solve it ?

 

my code as following:

 

            HttpWebRequest request = WebRequest.Create(requestURL) as HttpWebRequest;            
            request.Method = "POST";
            request.Accept = "application/json";
            request.ContentType = "application/json";

            // Add headers
            string authString = userId + ":" + password;
            var authStringBytes = System.Text.Encoding.UTF8.GetBytes(authString);
            string authHeaderString = Convert.ToBase64String(authStringBytes);
            request.Headers["Authorization"] = "Basic " + authHeaderString;

            // Load the body for the post request
            var requestStringBytes = System.Text.Encoding.UTF8.GetBytes(requestBodyString);
            request.GetRequestStream().Write(requestStringBytes, 0, requestStringBytes.Length);

            // Add certificate
            var certificate = new X509Certificate2(certificatePath, certificatePassword);
            request.ClientCertificates.Add(certificate);

        

            string responseBody = "";

            try
            {
                // Make the call
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    var encoding = ASCIIEncoding.ASCII;
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception(String.Format(
                         "Server error.\n\nStatusCode:{0}\n\nStatusDescription:{1}\n\nResponseHeaders:{2}",
                         response.StatusCode,
                         response.StatusDescription,
                         response.Headers.ToString()));
                    }

                    Console.WriteLine("Response Headers: \n" + response.Headers.ToString());

                    using (var reader = new StreamReader(response.GetResponseStream(), encoding))
                    {
                        responseBody = reader.ReadToEnd();
                    }

                    Console.WriteLine("Response Body: \n" + responseBody);
                }
            }
            catch (WebException e)
            {
                Console.WriteLine(e.Message);
            }

            return responseBody;
15 REPLIES 15
ricardo_visa
Community Scholar

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

Hi Utu, 

Lets see if these steps work: 

 

openssl pkcs12 -export -out p12certfile.p12 -inkey example-key.pem -in cert.pem

 

  • Use example-key.pem as private key which you have generated at the time of creation of CSR.
  • Use cert.pem as client certificate which you have downloaded from the VDP portal.
  • The above command will prompt for export password. You will need this password for invoking API.

 

Let me know if this works.

 

Thank you,

Ricardo

VDP Community Manager




Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.
kim
Regular Visitor

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

Hi I tried this one, but still The request was aborted: Could not create SSL/TLS secure channel. May i know what is the reason behind this? thanks!
shazia1
Newbie

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

 It worked !!

Utu
Regular Visitor

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

Hi ricardo_visa, I've already used this command to generate *.p12 file, followed visa 'Getting Started Guied', I also imported the key file to my keystone
kim
Regular Visitor

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

Hi I tried this one, but still The request was aborted: Could not create SSL/TLS secure channel. May i know what is the reason behind this? thanks!

ricardo_visa
Community Scholar

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

Hi Utu, 

There is a slight variation for C# from what’s on the Getting Started Guide.

 

Make .p12 again with these following commands: openssl pkcs12 -export -out p12certfile.p12 -inkey example-key.pem -in cert.pem

 

Hope this works - let me know!

 

-Ricardo




Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.
kim
Regular Visitor

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

Hi I tried this one, but still The request was aborted: Could not create SSL/TLS secure channel. May i know what is the reason behind this? thanks!

kim
Regular Visitor

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

Thanks! it is working now
mrticks
Regular Visitor

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

@Kim

How did you resolve this?

We are having the same issue. We followed the guide and SOAPUI is testing fine with 200 OK responses.