2016-06-14 83 views
1

我收到錯誤「請求已中止:無法創建SSL/TLS安全通道」。在沙箱的情況下,但這與我的現場憑證一起使用。錯誤Paypal沙箱:請求已中止:無法創建SSL/TLS安全通道

這裏是代碼片段

  var uri = new Uri(url); 
      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 
      var request = WebRequest.Create(uri); 
      var encoding = new UTF8Encoding(); 
      var requestData = encoding.GetBytes(postData); 

      request.ContentType = "application/x-www-form-urlencoded"; 
      request.Method = "POST"; 
      request.Timeout = (300 * 1000); //TODO: Move timeout to config 
      request.ContentLength = requestData.Length; 

      using (var stream = request.GetRequestStream()) 
      { 
       stream.Write(requestData, 0, requestData.Length); 
      } 

      var response = request.GetResponse(); 

      string result; 

      using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) 
      { 
       result = reader.ReadToEnd(); 
      } 

      return result; 

回答

2

的問題是C#默認爲SSL3嘗試連接到PayPal的服務器,貝寶不接受的時候。 PayPal至少需要(更安全的)TLS 1.2。

您設置此通過下面的代碼:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;  
+0

添加的代碼行提到,但仍同樣的錯誤。如果我在放置代碼時犯了錯誤,請參閱修改後的代碼。 –

+0

哇..它的工作對不起我的錯誤..我沒有建立它反映在我的項目......非常感謝 –

+0

啊,這是個好消息,我從生產代碼中解除了這一行,所以我有點不知所措可能。 :) –

相關問題