BigCommerce API 连接问题/开始时断断续续,现在更频繁
BigCommerce API Connection Problems / Began as Intermittent, now more frequent
我使用 API 将订单推送到我们客户的 BigCommerce 商店已经有一段时间了,但是,BigCommerce 最近开始拒绝连接 and/or 关闭连接。
我一直找不到问题的根源,我希望有经验的人and/or可以帮助找到这个问题的根源。
以下是我们现在收到的所有 Big Commerce API 请求的回复:
Message: The underlying connection was closed: An unexpected error occurred on a send.
InnerException: System.IO.IOException: Authentication failed because the remote party has closed the transport stream. at
System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32
readBytes, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer,
AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32
count, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,
Byte[] buffer, AsyncProtocolRequest asyncRequest) at
System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult
lazyResult) at
System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx) at
System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx) at
System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state) at
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();
}
}
}
}
现在每次都这样吗?如果不是,频率是多少?当您说 "rejecting connections and/or closing connections" 时,您是否看到针对每种情况的两种不同的错误响应?
我以前从 BC 看到过类似的消息,但只是来自格式错误的请求,这听起来不像你的情况,因为代码之前工作正常。我会在回家后 运行 进行一些测试,看看是否遇到了类似的问题,并且我会比较代码以查看是否存在差异。
编辑:post 我正在使用的代码的一个非常简化的版本可能更有帮助。我有一个辅助方法 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;
}
您应该能够修改它以验证您是否可以始终如一地从您的站点检索订单。
与 BC 对应后,似乎在 BC API 服务器上禁用了 TLS 1.0,导致来自我的 Windows 2008 R2 服务器 运行 IIS 的请求出现问题.
SSL 3.0 之前已被 BC 禁用,这并没有在 IIS 上为我抛出错误,因为 SSL 3.0 在我的服务器上也已被禁用。
对于那些遇到类似问题的人,建议禁用 SSL 和 TLS 1.0(BC 将在不久的将来弃用 TLS 1.0 协议),只保留较新的协议。
来自 BC 的进一步说明:
*只是为了更新你 - 我们能够在 Windows Server 2008 机器上重现这些相同的问题。它看起来确实像 TLS/SSL 协商,特别是因为 2k8 仅支持 SSLv3(已禁用很长时间)和 TLS 1.0。作为迁移到较新负载均衡器的一部分,我们禁用了 TLS 1.0 [已删除],我们的理解是我们应该担心 Windows Vista 及更低版本。不幸的是,2k8 共享相同的密码配置。
[已删除]
我将与我们的团队合作,在接下来的一个月左右积极弃用 API 流量的 TLSv1.0 和不安全密码。这只是我们今天流量的一小部分。我们会就此进行适当的沟通,但它会迫使您迁移到更新的操作系统。
*
我使用 API 将订单推送到我们客户的 BigCommerce 商店已经有一段时间了,但是,BigCommerce 最近开始拒绝连接 and/or 关闭连接。
我一直找不到问题的根源,我希望有经验的人and/or可以帮助找到这个问题的根源。
以下是我们现在收到的所有 Big Commerce API 请求的回复:
Message: The underlying connection was closed: An unexpected error occurred on a send.
InnerException: System.IO.IOException: Authentication failed because the remote party has closed the transport stream. at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at 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();
}
}
}
}
现在每次都这样吗?如果不是,频率是多少?当您说 "rejecting connections and/or closing connections" 时,您是否看到针对每种情况的两种不同的错误响应?
我以前从 BC 看到过类似的消息,但只是来自格式错误的请求,这听起来不像你的情况,因为代码之前工作正常。我会在回家后 运行 进行一些测试,看看是否遇到了类似的问题,并且我会比较代码以查看是否存在差异。
编辑:post 我正在使用的代码的一个非常简化的版本可能更有帮助。我有一个辅助方法 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;
}
您应该能够修改它以验证您是否可以始终如一地从您的站点检索订单。
与 BC 对应后,似乎在 BC API 服务器上禁用了 TLS 1.0,导致来自我的 Windows 2008 R2 服务器 运行 IIS 的请求出现问题.
SSL 3.0 之前已被 BC 禁用,这并没有在 IIS 上为我抛出错误,因为 SSL 3.0 在我的服务器上也已被禁用。
对于那些遇到类似问题的人,建议禁用 SSL 和 TLS 1.0(BC 将在不久的将来弃用 TLS 1.0 协议),只保留较新的协议。
来自 BC 的进一步说明:
*只是为了更新你 - 我们能够在 Windows Server 2008 机器上重现这些相同的问题。它看起来确实像 TLS/SSL 协商,特别是因为 2k8 仅支持 SSLv3(已禁用很长时间)和 TLS 1.0。作为迁移到较新负载均衡器的一部分,我们禁用了 TLS 1.0 [已删除],我们的理解是我们应该担心 Windows Vista 及更低版本。不幸的是,2k8 共享相同的密码配置。
[已删除]
我将与我们的团队合作,在接下来的一个月左右积极弃用 API 流量的 TLSv1.0 和不安全密码。这只是我们今天流量的一小部分。我们会就此进行适当的沟通,但它会迫使您迁移到更新的操作系统。 *