它在一周之前运作良好,但现在它显示以下错误。我尝试过以下的东西,但没有用。
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;
}
答案 0 :(得分:38)
我刚刚在我的测试环境中遇到了同样的问题(幸运的是我的实时付款正在进行中)。我修改了它:
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的评论更新的thx)声明:
PayPal正在更新其服务,要求所有HTTPS都需要TLS 1.2 连接。此时,PayPal还需要HTTP / 1.1 连接... 为避免服务中断,您必须在2016年6月17日之前验证您的系统是否已准备好进行此更改
答案 1 :(得分:22)
确实更改 SecurityProtocolType.Tls 修复了问题,如果您在VS中使用低于4.5的框架而无法更改它,则必须将VS升级为最高版本2012/2013/2015更改它。
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType的 Tls12 强>;
答案 2 :(得分:8)
将以下代码添加到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/
答案 3 :(得分:0)
如果您的框架版本低于4.5,则可能无法直接进行设置。您可以使用以下代码
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;