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

2

5

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);
Fishman answered 22/1, 2016 at 10:56 Comment(3)
I started to see this happening a day or so ago. Perhaps an issue with the certificate of sandbox.paypal.com?Barbarity
9-10 months ago it doesn't throws any error with sandbox. Is it issue of sandbox?Fishman
Also this code works with paypal account successfully. It happens with sandbox account only. So it is issue of sandbox account?Fishman
P
18

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;
Pennebaker answered 22/1, 2016 at 15:58 Comment(4)
Thank you very much @nqynik. This resolved my issue.Fishman
This answer helps me too. One thing that you should add in your answer: SecurityProtocolType.Tls12 is only available in .NET 4.5 or above, so if the target framework is .NET 4.0 then you will need to change the target framework.Persiflage
You are a savior. Hopefully Microsoft updates its PayPal tutorial!!1Dollhouse
If you are using .Net 4.0 then you wouldn't get option for SecurityProtocolType.Tls12, in that case you can use following code: ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Tls12 As given at this link- #34940023Rice
C
0

The answer that worked for us was listed on the PayPal blog post, Upcoming Security Changes Notice. There are a number of things listed in the post, but the one thing which we did, and that worked, was PayPal SDK Updates. We updated using NuGet and everything started working again.

Choleric answered 22/1, 2016 at 18:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.