【问题标题】:Error Paypal sandbox: The request was aborted: Could not create SSL/TLS secure channel错误 Paypal 沙箱:请求被中止:无法创建 SSL/TLS 安全通道
【发布时间】:2016-10-14 18:30:31
【问题描述】:

我收到错误“请求已中止:无法创建 SSL/TLS 安全通道。”但是,在沙盒的情况下,这适用于我的实时凭据。

这里是代码sn-p

            var uri = new Uri(url);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            var request = WebRequest.Create(uri);
            var encoding = new UTF8Encoding();
            var requestData = encoding.GetBytes(postData);

            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";
            request.Timeout = (300 * 1000); //TODO: Move timeout to config
            request.ContentLength = requestData.Length;

            using (var stream = request.GetRequestStream())
            {
                stream.Write(requestData, 0, requestData.Length);
            }

            var response = request.GetResponse();

            string result;

            using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
            {
                result = reader.ReadToEnd();
            }

            return result;

【问题讨论】:

    标签: c# asp.net-mvc-4 paypal paypal-sandbox


    【解决方案1】:

    问题是 C# 在尝试连接到 PayPal 服务器时默认使用 SSL3,而 PayPal 不接受该服务器。 PayPal 至少需要(更安全的)TLS 1.2。

    您可以通过以下代码进行设置:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;       
    

    【讨论】:

    • 添加了提到的代码行但仍然是同样的错误。如果我在放置代码时出错,请查看修改后的代码。
    • 哇..它的工作对不起我的错误..我没有构建它来反映在我的项目中......非常感谢
    • 啊,这是个好消息,我从生产代码中删除了这一行,所以我有点不知所措。 :)
    猜你喜欢
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 2018-04-22
    • 2012-10-30
    相关资源
    最近更新 更多