HttpWebRequest 超时更新 BigCommerce 中的状态代码

我已经阅读了很多关于 Web 请求超时的帖子(如果不是全部的话),并且提供的解决方案没有奏效。我从 Big Commerce 收到订单,然后更新 Big Commerce 状态代码。我可以更新 2 个订单,然后在第三个订单超时,每次都不管星期几或一天中的时间。

App.Config 文件具有:

```
<system.web>
    <httpruntime executionTimeout="180" />
</system.web>
```

代码:

```
    Try
        Dim strJSON As String = "{""status_id"": 9}"
        Dim postBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(strJSON)
        For i As Integer = 0 To dto.Rows.Count - 1
            strWebOrder = dto.Rows(i).Item("WebOrder")
            Dim strHttp As String = "https://api.bigcommerce.com/stores/storeid/v2/orders/" & strWebOrder
            Dim request As HttpWebRequest = DirectCast(WebRequest.Create(strHttp),HttpWebRequest)
            request.accept = "application/json"
            request.ContentType = "application/json"
            request.Headers("X-Auth-Token") = strauthToken
            request.Timeout = 10000
            request.AllowWriteStreamBuffering = False
            request.SendChunked = True
            request.Method = "PUT"
            Dim postStream As Stream = request.GetRequestStream()
            postStream.Write(postBytes,postBytes.Length)
            Dim response As Httpwebresponse = DirectCast(request.GetResponse(),Httpwebresponse)
            If response.StatusCode = 200 Then
                strErrorRef = "Web " & strWebOrder
                strErrorReason = "Order Status Changed to Exported"
                strPutMessage = ""
                WriteError()
            Else
                strErrorRef = "Web " & strWebOrder
                strErrorReason = "Unable to change Web Order Status to Exported"
                strPutMessage = ""
                WriteError()
            End If
        Next
    Catch ex As Exception
        strErrorRef = "Web " & strWebOrder
        strErrorReason = "Unable to change Web Order Status to Exported"
        strPutMessage = (ex.ToString)
        WriteError()
    End Try
```
wuxiaoxun 回答:HttpWebRequest 超时更新 BigCommerce 中的状态代码

您是否尝试过增加 executionTimeout 属性中的秒数?如果您将其增加到 300,这将使您的应用程序在关闭之前有 5 分钟的时间执行命令,而不是您当前使用的 3 分钟。

我不确定您尝试或阅读的所有内容,但听起来您拥有的代码至少需要 2-3 分钟才能完成 2 个订单,所以这就是您看到的结果相同的原因无论它在一天中的什么时间被执行。

您是否尝试过重构代码以将其分解一下,例如: 在一个函数中获取 status_id 为 9 的所有订单或 将这些 order_id 存储在其他地方的另一个函数中的数组中,然后在新函数中循环遍历存储的数组以更新 status_id?

另外,您是否在使用网络钩子?

本文链接:https://www.f2er.com/1177962.html

大家都在问