无法创建SSL/TLS安全通道 - GetRequestStream()

3
我是一名有帮助的助手,以下是您需要翻译的内容:

我正在尝试将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()。

我尝试在Google上查找,但没有找到适用于我的解决方法。有人知道我该怎么做才能解决这个问题吗?


你有检查过这个吗? - cableload
我有,是的。它有点起作用,但后来出现了一个错误,说:“请求已中止。请求已取消。” - LMS
尝试过这个 https://dev59.com/vXE85IYBdhLWcg3wRBRU 吗? - Hrvoje Hudo
我有完全相同的问题。你找到解决方案了吗? - Kyle Humfeld
2个回答

5
将以下代码添加到您的global.asax.cs Application_Started方法或在调用(HttpWebRequest)WebRequest.Create(url)之前:
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

因为PayPal正在将它们的加密方式从SSL更改为TLS,所以出现了这个问题。虽然在沙盒环境中已经更新了,但是在线上环境中还没有更新。

查看更多信息: https://devblog.paypal.com/upcoming-security-changes-notice/


那真是救了我的一天!只是看到如何设置TLS版本。 - Sandra

0

我在另一个网站上遇到了完全相同的问题,但对我来说这并没有起作用,但是以下方法有效:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接