它在一周之前运作良好,但现在它显示以下错误。我尝试过以下的东西,但没有用。
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
所以建议我可能的解决方案
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;
}
我刚刚在我的测试环境中遇到了同样的问题(幸运的是我的实时付款正在进行中)。我修改了它:
public PayPalAPI(string specialAccount = "")
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
至
public PayPalAPI(string specialAccount = "")
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
他们不久前禁用了对SSL3的支持:https://www.paypal.com/uk/webapps/mpp/ssl-security-update,具体说明
确保使用TLS 1.0或1.2连接到PayPal端点(并非所有API端点当前都支持TLS 1.1)。
他们的latest update(来自@awesome的评论更新)表示:
PayPal正在更新其服务,要求所有HTTPS连接都使用TLS 1.2。此时,PayPal还需要HTTP / 1.1用于所有连接...为避免服务中断,您必须在2016年6月17日之前验证您的系统是否已准备好进行此更改
确实更改SecurityProtocolType.Tls可以解决问题,如果您在VS中使用低于4.5的框架而无法更改它,则必须将VS升级到最高版本2012/2013/2015以进行更改。
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
将以下代码添加到global.asax或在调用(HttpWebRequest)WebRequest.Create(url)之前;
protected void Application_Start()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// ...
}
这是因为PayPal正在将其加密更改为TLS而不是SSL。这已在Sandbox环境中更新,但尚未在实时更新。
阅读更多:https://devblog.paypal.com/upcoming-security-changes-notice/
如果您的框架版本低于4.5,则可能无法直接设置它。您可以使用以下代码
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;