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

chi*_*tra 5 asp.net-mvc paypal paypal-sandbox nopcommerce

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

请求已中止:无法创建SSL/TLS安全通道.

我也使用Paypal的Sandbox帐户进行测试.

它从这一行抛出错误:

var sw = new StreamWriter(req.GetRequestStream()
Run Code Online (Sandbox Code Playgroud)

这是下面的代码:

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);
Run Code Online (Sandbox Code Playgroud)

nqy*_*nik 17

我有同样的问题连接到沙盒(nvp),一切都很好,然后昨天消息"请求被中止:无法创建SSL/TLS安全通道." 出现了.

我相信PayPal在2016年1月19日更新了他们的终端,以使用TSL 1.2和HTTP 1.1.

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

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Run Code Online (Sandbox Code Playgroud)