.net 请求被中止:无法创建 SSL/TLS 安全通道沙箱帐户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34939523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:45:08  来源:igfitidea点击:

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

.netpaypalsandbox

提问by vellai durai

It was working well before a week but now it shows following error. I have tried the following things but of no use.

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

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

so suggest me with possible solution

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

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

回答by MikeSmithDev

I just ran into this same problem in my testing environment as well (luckily my live payments are going through). I fixed it by changing:

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

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

to

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

They disabled support for SSL3 a while ago: https://www.paypal.com/uk/webapps/mpp/ssl-security-update, specifically stating

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

Ensure you are connecting to PayPal endpoints using TLS 1.0 or 1.2 (not all API endpoints currently support TLS 1.1).

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

Their latest update(thx for the comment update from @awesome) states:

他们的最新更新(感谢@awesome 的评论更新)指出:

PayPal is updating its services to require TLS 1.2 for all HTTPS connections. At this time, PayPal will also require HTTP/1.1 for all connections... To avoid any disruption of service, you must verify that your systems are ready for this change by June 17, 2016

PayPal 正在更新其服务,要求所有 HTTPS 连接都使用 TLS 1.2。目前,PayPal 还将要求所有连接使用 HTTP/1.1...为避免任何服务中断,您必须在 2016 年 6 月 17 日之前确认您的系统已准备好应对此更改

回答by Gonzdn

Indeed changing SecurityProtocolType.Tlsfixes the problem, if you′re working in VS with a framework lower than 4.5 you won′t be able to change it, you have to upgrade your VS to a highest version 2012/2013/2015 to change it.

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

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

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType。tls12;

回答by Kevin Farrugia

Add the following code to your global.asax or before calling the (HttpWebRequest)WebRequest.Create(url);

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

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

This was caused because PayPal are changing their encryption to TLS instead of SSL. This has already been updated on the Sandbox environments but not yet on the live.

这是因为 PayPal 正在将其加密更改为 TLS 而不是 SSL。这已经在沙盒环境中更新,但还没有在现场。

Read more: https://devblog.paypal.com/upcoming-security-changes-notice/

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

回答by user2081126

If your framework version is less than 4.5, you might not be able to set it directly. You can use the below code

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

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;