I’m making a asp.net web forms application which offers to pay using paypal. The application is supposed to make use of ssl. When i run my application all goes well until i select my button pay by paypal. When i press this button the following error occurs:
The request was aborted: Could not create SSL/TLS secure channel.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.Exception Details: System.Net.WebException: The request was aborted:
Could not create SSL/TLS secure channel.Source Error:
Line 203: Line 204: //Retrieve the Response returned from the
NVP API call to PayPal. Line 205: HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse(); Line 206: string
result; Line 207: using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))Source File: C:Userswillemdocumentsvisual studio
2015ProjectsWingtipToysWingtipToysLogicPayPalFunctions.cs
Line: 205
Below my method in which the error ocurs
public string HttpCall(string NvpRequest)
{
string url = pEndPointURL;
string strPost = NvpRequest + "&" + buildCredentialsNVPString();
strPost = strPost + "&BUTTONSOURCE=" + HttpUtility.UrlEncode(BNCode);
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Timeout = Timeout;
objRequest.Method = "POST";
//objRequest.ContentLength = strPost.Length;
try
{
using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
{
myWriter.Write(strPost);
}
}
catch (Exception)
{
// No logging for this tutorial.
}
//Retrieve the Response returned from the NVP API call to PayPal.
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
string result;
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
}
return result;
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Your code snippet does not specify the security protocol to use from what I can tell –
Example:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
I found this after looking at different authentication methods against the paypal api.
There is a related topic here that deserves the credit. problems-with-paypal-api-http-call
Note: This answer was added after the string of comments on the original OP question.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0