请求已中止:无法创建 SSL/TLS 安全 channel.System.Net.WebException

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

我正在使用 NopCommerce 的 PayPalStandard 插件。当我在 paypal 上成功付款后使用 paypalstandard 插件下订单并付款时,它会重定向到商家网站。当时报错:

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

另外我正在使用Paypal的沙盒账户进行测试。

它从这一行抛出错误:

var sw = new StreamWriter(req.GetRequestStream()

下面是代码:

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);

我在连接到沙箱 (nvp) 时遇到了同样的问题,一切正常,然后昨天出现了 "The request was aborted: Could not create SSL/TLS secure channel." 消息。

我相信 PayPal 在 2016 年 1 月 19/20 日更新了他们的端点以使用 TSL 1.2 和 HTTP 1.1。

要解决此问题,对于 .NET 4.5 及更高版本,请在调用 WebRequest.Create() 之前添加以下代码行。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

PayPal 博客 post、Upcoming Security Changes Notice 上列出了对我们有用的答案。 post 中列出了很多事情,但我们所做的一件事是 PayPal SDK 更新 。我们使用 NuGet 进行了更新,一切都重新开始工作。