2017-03-01 19 views
1

我一直在使用API​​將訂單推送到客戶的BigCommerce商店很長一段時間,但是,BigCommerce最近開始拒絕連接和/或關閉連接。BigCommerce API連接問題/開始爲間歇性,現在更頻繁

我一直無法找到問題的根源,我希望有人經歷過和/或可以幫助找到此問題的根源。

以下是現在,我們正在對所有大商業API請求的響應:

消息:基礎連接已關閉:上一個發送發生意外的錯誤。

InnerException: System.IO.IOException:驗證失敗,因爲遠程方關閉了傳輸流。在 System.Net.Security.SslState.StartReadFrame(字節[]緩衝液,的Int32 的ReadBytes,AsyncProtocolRequest asyncRequest)在 System.Net.Security.SslState.StartReceiveBlob(字節[]緩衝液, AsyncProtocolRequest asyncRequest)在 System.Net .Security.SslState.StartSendBlob(字節[]來電,的Int32 計數,AsyncProtocolRequest asyncRequest)在 System.Net.Security.SslState.ForceAuthentication(布爾receiveFirst, 字節[]緩衝液,AsyncProtocolRequest asyncRequest)在 System.Net.Security .SslState.ProcessAuthentication(LazyAsyncResult lazyResult)at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,Co ntextCallback回調,對象的狀態,布爾 preserveSyncCtx)在 System.Threading.ExecutionContext.Run(的ExecutionContext 的ExecutionContext,ContextCallback回調,對象的狀態,布爾 preserveSyncCtx)在 System.Threading.ExecutionContext.Run(的ExecutionContext 的ExecutionContext,ContextCallback回調,對象狀態) System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)at System.Net.TlsStream.Write(Byte [] buffer,Int32 offset,Int32 size)at System.Net.ConnectStream.WriteHeaders(Boolean async )

req = (HttpWebRequest)WebRequest.Create(baseURL); 
    req.AllowAutoRedirect = true; 
    req.ContentType = "application/json"; 
    req.Accept = "application/json"; 
    req.Method = "GET"; 

    req.Headers.Add("X-Auth-Client", clientID); 
    req.Headers.Add("X-Auth-Token", AccessToken); 
    req.Headers.Add("Authorization", authValue); 

    using (WebResponse resp = req.GetResponse()) { 
     if (req.HaveResponse && resp != null) { 
      using (var reader = new StreamReader(resp.GetResponseStream())) { 
        jsonResponse = reader.ReadToEnd(); 
       } 
      } 
     } 
    } 
+0

似乎與SSL有關。你可以忽略證書驗證嗎?或者顯示ssl相關的代碼? – 2017-03-02 03:32:18

回答

1

與BC相對應後,BC API服務器上似乎已禁用TLS 1.0,導致運行IIS的Windows 2008 R2服務器發出請求時出現問題。

BC 3.0之前已禁用SSL 3.0,它在IIS上並沒有爲我丟失錯誤,因爲我的服務器上也禁用了SSL 3.0。

對於遇到類似問題的用戶,建議禁用SSL以及TLS 1.0(TLS 1.0協議將在不久的將來由BC不贊成使用),只留下較新的協議。

從公元前其它注意事項:

*只需更新您 - 我們能夠重現Windows Server 2008的計算機上,這些相同的問題。它看起來像TLS/SSL協商,特別是因爲2k8僅支持SSLv3(長時間禁用)和TLS 1.0。我們禁用TLS 1.0 [刪除]作爲我們遷移到新的負載平衡器的一部分,我們的理解是我們應該擔心Windows Vista及更低版本。不幸的是,2k8共享相同的密碼配置。

[刪除]

我將與我們的團隊將在未來一個月左右的時間積極棄用TLSv1.0和不安全的密碼爲API業務合作。今天的流量非常少。我們會圍繞此進行適當的溝通,但這會迫使您轉向更新的操作系統。 *

1

現在每一次都在發生嗎?如果不是,頻率是多少?當你說「拒絕連接和/或關閉連接」時,你是否看到針對每種情況的兩種不同的錯誤響應?

我以前從BC看過類似的消息,但只能從格式錯誤的請求中看到,這聽起來不像您的情況,因爲之前的代碼工作正常。當我回家時,我會運行一些測試,看看是否有類似的問題,並且會比較代碼以查看是否存在差異。

編輯:它可能會更有用,只是發佈我正在使用的代碼的非常簡化的版本。我有一個輔助方法,BigCommerceGet,這是從我的代碼中多個地方叫:

private string BigCommerceGet(string URL) 
{ 
    System.Net.HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseUrl + URL); 
    req.Credentials = new NetworkCredential(_username, _api_key); 
    req.AllowAutoRedirect = true; 
    req.ContentType = "application/json"; 
    req.Accept = "application/json"; 
    req.Method = "GET"; 

    string jsonResponse = null; 
    using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse) 
    { 
     if (req.HaveResponse && resp != null) 
     { 
      using (var reader = new StreamReader(resp.GetResponseStream())) 
      { 
       jsonResponse = reader.ReadToEnd(); 
      } 
     } 
    } 

    return jsonResponse; 
} 

這裏有一個循環我用它來從我的站點檢索所有的訂單,並將其寫入文件:

public Order[] GetAllOrders() 
{ 
    Order[] result = null; 
    string orderString = ""; 

    try 
    { 
     StringBuilder orders = new StringBuilder("["); 
     String jsonResponse = BigCommerceGet("orders?limit=50&page=1"); 
     int page = 1; 
     string prePend = ""; 

     while (jsonResponse != "") 
     { 
      // Remove the leading and trailing brackets, and prepend a comma 
      // beyond page 1. 
      orders.Append(prePend + jsonResponse.Substring(1, jsonResponse.Length - 2)); 
      prePend = ","; 
      page++; 
      jsonResponse = BigCommerceGet("orders?limit=50&page=" + page.ToString()); 
     } 

     orders.Append("]"); 

     System.IO.FileStream wFile; 
     byte[] byteData = null; 
     byteData = Encoding.ASCII.GetBytes(orders.ToString()); 
     using (wFile = new FileStream(@"Z:\ThisIsYourFile.txt", FileMode.Create)) 
     { 
      wFile.Write(byteData, 0, byteData.Length); 
      wFile.Close(); 
     } 

     orderString = orders.ToString(); 
     result = JsonConvert.DeserializeObject<Order[]>(orderString); 
    } 
    catch (Exception e) 
    { 
     Console.WriteLine("*** Exception encountered while retrieving store information: {0}", e.ToString()); 
    } 

    return result; 
} 

您應該可以修改此項以驗證您是否可以始終從您的網站檢索訂單。

+0

大約一個星期前它開始偶爾發生,沒有發生與每個請求一致。來自BC的錯誤響應總是相同的。我們的結局沒有任何變化,我們已經使用相同的代碼一年或更長時間沒有問題。似乎BC現在可能需要某種類型的安全連接? – brendo234

+1

感謝您提供更多的信息,但事實證明這是TLS/SSL協商問題。評論在下面的答案中提到。 – brendo234