gpt4 book ai didi

c# - Paypal IPN 问题 - 请求被中止 : Could not create SSL/TLS secure channel

转载 作者:太空宇宙 更新时间:2023-11-03 21:14:31 31 4
gpt4 key购买 nike

我正在使用 paypal sandox 来测试支付网关。问题出在支付成功后调用的IPN代码。我正在使用的代码运行良好,但自上个月以来突然停止工作。我不确定发生了什么,它与 paypal 在其 github 存储库中提供的代码完全相同。有人可以指导我正确的方向吗?

这是我用于 IPN Controller 的代码

public ActionResult Index()
{
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
//string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);

//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] Param = Request.BinaryRead(System.Web.HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(Param);
strRequest = strRequest + "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;

//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();

if (strResponse == "VERIFIED")
{
//check the payment_status is Completed
//check that txn_id has not been previously processed
//check that receiver_email is your Primary PayPal email
//check that payment_amount/payment_currency are correct
//process payment
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
else
{
//Response wasn't VERIFIED or INVALID, log for manual investigation
}
return View();
}

错误信息是这样的:

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

它在这条线上中断

 //Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);

我已经搜索了与此错误相关的现有帖子,但它们的日期已经很久了。但是从上个月开始我就开始遇到这个错误。所以,可能是 Paypal 的一些重大变化,我不知道。有人可以帮我吗?非常感谢。

最佳答案

在您的行上方添加以下内容:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);

我一直在使用 PayPal(NVP/签名)Express Checkout 集成,但遇到了这个 SSL/TLS 错误。

我所做的一切似乎都无法解决,但后来我发现将以下代码添加到我的请求之上。作为引用,我使用的是 MVC3/.NET 4,因此默认情况下 Tls1.2 对我不可用(就像在 .NET 4.5 + 中一样)。这段代码的前三行解决了这个问题。我希望它能帮助人们!

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.DefaultConnectionLimit = 9999;

关于c# - Paypal IPN 问题 - 请求被中止 : Could not create SSL/TLS secure channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35309193/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com