Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:\Users\willem\documents\visual studio 2015\Projects\WingtipToys\WingtipToys\Logic\PayPalFunctions.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;
}
like image 772
WillemKoonings Avatar asked Mar 15 '16 08:03

WillemKoonings


People also ask

Why the request was aborted could not create SSL TLS secure channel?

The error “The request was aborted: Could not create SSL/TLS secure channel.” can happen during any download HTTP request. This error generally will correspond to firewalls, proxies or DNS filtering blocking the connection or an SSL/TLS cipher misconfiguration.

Can't create SSL TLS secure channel IIS?

However, the "Could not create SSL/TLS secure channel" error usually means that there's something wrong with the server certificate, e.g. the certificate is for a different hostname, or otherwise invalid, or not trusted etc.

What is an SSL TLS secure channel?

TLDR: SSL/TLS encrypts communications between a client and server, primarily web browsers and web sites/applications. SSL (Secure Sockets Layer) encryption, and its more modern and secure replacement, TLS (Transport Layer Security) encryption, protect data sent over the internet or a computer network.


1 Answers

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.

like image 73
Elmar Avatar answered Sep 25 '22 19:09

Elmar