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

chitra picture chitra · Jan 22, 2016 · Viewed 11.1k times · Source

I am using PayPalStandard plugin of NopCommerce. When I placed the order & make payment with paypalstandard plugin after successful payment on paypal, it redirects to merchants site. At that time it gives error:

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

Also I am using Sandbox account of Paypal for testing.

It throws error from this line:

var sw = new StreamWriter(req.GetRequestStream()

Here is code below:

var req = (HttpWebRequest)WebRequest.Create(GetPaypalUrl());
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.ProtocolVersion = HttpVersion.Version10;

        string formContent = string.Format("cmd=_notify-synch&at={0}&tx={1}", _paypalStandardPaymentSettings.PdtToken, tx);
        req.ContentLength = formContent.Length;

        using (var sw = new StreamWriter(req.GetRequestStream(), Encoding.ASCII))
            sw.Write(formContent);

Answer

nqynik picture nqynik · Jan 22, 2016

I had the same issue connecting to sandbox(nvp), everything was fine then yesterday the message "The request was aborted: Could not create SSL/TLS secure channel." appeared.

I believe PayPal updated their endpoints on 19/20 January 2016 to use TSL 1.2 and HTTP 1.1.

To resolve this, for .NET 4.5 and above add the following line of code before calling WebRequest.Create().

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;