【问题标题】:Could not create SSL/TLS secure channel - GetRequestStream()无法创建 SSL/TLS 安全通道 - GetRequestStream()
【发布时间】:2016-08-03 03:37:14
【问题描述】:

我正在尝试将 paypal 集成到 Web 应用程序中,但没有成功。我已经尝试了很多东西,但我一直回到一个特定的错误。我现在正在尝试使用 paypal 集成向导,当我获得提供的代码时,我收到一条错误消息:请求已中止:无法创建 SSL/TLS 安全通道。

这是代码:

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

    HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
    objRequest.Timeout = Timeout;
    objRequest.Method = "POST";
    objRequest.ContentLength = strPost.Length;
    StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream());

错误发生在最后一行,objRequest.GetRequestStream()

我尝试在谷歌上查找它,但我没有找到任何适合我的东西。 有人知道我能做些什么来解决这个问题吗?

【问题讨论】:

  • 你检查过this 吗?
  • 我有,是的。它有点工作,但后来我收到一条错误消息:请求被中止。请求被取消
  • 我有这个确切的问题。你找到解决方案了吗?

标签: asp.net ssl paypal


【解决方案1】:

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

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

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

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

【讨论】:

  • 这拯救了我的一天!只是看看如何设置 TLS 版本。
【解决方案2】:

我在不同的网站上遇到了完全相同的问题,但对我来说这不起作用,但以下是可行的:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

【讨论】:

    猜你喜欢
    • 2021-12-13
    • 2014-12-26
    • 2017-02-10
    • 2017-08-22
    • 2018-06-17
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2018-12-19
    相关资源
    最近更新 更多