【问题标题】:The request was aborted: Could not create SSL/TLS secure channel sandbox account请求中止:无法创建 SSL/TLS 安全通道沙箱帐户
【发布时间】:2016-04-28 15:06:15
【问题描述】:

它在一周前运行良好,但现在显示以下错误。我尝试了以下方法,但没有用。

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

所以建议我提供可能的解决方案

public string HttpCall(string NvpRequest) //CallNvpServer
    {
        string url = pendpointurl;

        //To Add the credentials from the profile
        string strPost = NvpRequest + "&" + buildCredentialsNVPString();
        strPost = strPost + "&BUTTONSOURCE=" + HttpUtility.UrlEncode(BNCode);

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
        // allows for validation of SSL conversations
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };


        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 e)
        {
            /*
            if (log.IsFatalEnabled)
            {
                log.Fatal(e.Message, this);
            }*/
        }

        //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();
        }

        //Logging the response of the transaction
        /* if (log.IsInfoEnabled)
         {
             log.Info("Result :" +
                       " Elapsed Time : " + (DateTime.Now - startDate).Milliseconds + " ms" +
                      result);
         }
         */
        return result;
    }

【问题讨论】:

  • 有任何更新吗?我也面临同样的问题。

标签: .net paypal sandbox


【解决方案1】:

我刚刚在我的测试环境中也遇到了同样的问题(幸运的是我的实时付款正在通过)。我通过更改来修复它:

public PayPalAPI(string specialAccount = "")
{
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;

public PayPalAPI(string specialAccount = "")
{
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

他们不久前禁用了对 SSL3 的支持:https://www.paypal.com/uk/webapps/mpp/ssl-security-update,具体说明

确保您使用 TLS 1.0 或 1.2 连接到 PayPal 端点 (目前并非所有 API 端点都支持 TLS 1.1)。

他们的latest update(感谢@awesome 的评论更新)表示:

PayPal 正在更新其服务,要求所有 HTTPS 都使用 TLS 1.2 连接。此时,PayPal 也将要求所有的 HTTP/1.1 连接... 为避免任何服务中断,您必须在 2016 年 6 月 17 日之前验证您的系统是否已准备好进行此更改

【讨论】:

【解决方案2】:

确实更改 SecurityProtocolType.Tls 解决了这个问题,如果您在 VS 中使用低于 4.5 的框架工作,您将无法更改它,您必须将您的 VS 升级到最高版本 2012/2013/2015 来改变它。

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

【讨论】:

  • 实际上你可以像这样使用它(至少在 4.0 中):ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
  • 这是非常有帮助的@JamesMcCormack
  • 谢谢,它使用 ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; 非常适合 .Net 4.0;请检查-joymonscode.blogspot.in/2015/08/…
【解决方案3】:

将以下代码添加到您的 global.asax 中或在调用 (HttpWebRequest)WebRequest.Create(url);之前添加;

protected void Application_Start()
{
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    // ...
}

这是因为 PayPal 将其加密更改为 TLS 而不是 SSL。这已在沙盒环境中更新,但尚未上线。

阅读更多: https://devblog.paypal.com/upcoming-security-changes-notice/

【讨论】:

    【解决方案4】:

    如果您的框架版本低于 4.5,您可能无法直接设置。您可以使用以下代码

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    

    【讨论】:

      猜你喜欢
      • 2016-10-14
      • 2021-02-27
      • 2012-06-05
      • 2018-04-22
      • 2012-10-30
      • 1970-01-01
      相关资源
      最近更新 更多