2016-01-22 85 views
34

它在一周前运行良好,但现在它显示以下错误。我尝试了以下的东西,但没用。请求已中止:无法创建SSL/TLS安全通道沙箱帐户

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

对此有何更新?我也面临同样的问题。 – Saurabh

回答

35

我只是碰到了在我的测试环境中,这同样的问题,以及(幸运的是我的生活支付正在经历)。我通过改变固定它:

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 (并非所有API端点当前都支持TLS 1.1)。

他们latest update(THX从@awesome注释更新)指出:

贝宝正在更新其服务要求TLS 1.2所有HTTPS连接 。这时,贝宝还需要HTTP/1.1所有 连接...... 为了避免服务的任何破坏,您必须验证您的系统已经准备好通过6月17日这一变化2016

+1

官方新闻https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=zh_CN –

+0

感谢堆!正是我需要的。 – Brendan

22

事实上改变SecurityProtocolType.Tls解决了这个问题,如果你在VS下工作的框架低于4.5你不能改变它,你必须升级你的VS到最高版本2012/2013/2015来改变它。

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType。 Tls12;

+27

其实你*可以*使用它(至少在4.0)像这样: 'ServicePointManager.SecurityProtocol =(SecurityProtocolType)3072; // SecurityProtocolType.Tls12' –

+0

@James McCormack:非常感谢,有一个upvote。 –

+0

这是非常非常有用的@JamesMcCormack – scgough

7

下面的代码添加到您的Global.asax或致电(HttpWebRequest的)WebRequest.Create(URL)之前;

protected void Application_Start() 
{ 
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 
    // ... 
} 

这是因为PayPal正在将其加密更改为TLS而不是SSL。这已经在沙盒环境中进行了更新,但尚未在现场进行更新。

了解更多: https://devblog.paypal.com/upcoming-security-changes-notice/

相关问题