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;
Hi Utu,
Lets see if these steps work:
openssl pkcs12 -export -out p12certfile.p12 -inkey example-key.pem -in cert.pem
Let me know if this works.
Thank you,
Ricardo
VDP Community Manager
It worked !!
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!
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
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!