我有一个使用VBA构建的Excel加载项,并且我的一个用户在尝试发布到基于云的API时遇到请求超时。我正在使用VBA-Web工具https://github.com/VBA-tools/VBA-Web发出HTTP请求。
Dim Request As New WebRequest
Request.Resource = Resource 'my api endpoint
Request.Method = WebMethod.HttpPost
Request.Format = WebFormat.Json
Request.ResponseFormat = WebFormat.Json
Request.AddHeader "Authorization","Bearer " & SessionKey
Client.TimeoutMs = 15000
Set Request.Body = Body 'a dictionary with user data
Dim Response As webresponse
Set Response = Client.Execute(Request)
If Response.StatusCode <> Ok Then
Debug.Print Response.StatusCode
Debug.Print Response.StatusDescription
End If
我已经要求用户将其日志发送给我,它们看起来像这样:
Response.StatusCode
Response.StatusDescription
>> 408
>> Request Timeout: The operation timed out
我最初以为这是防火墙问题,因为除了一组用户(位于同一建筑物内)外,没有人报告此问题,但是我已经要求他们在其互联网浏览器中导航到该URL,能够得到回应。
这很不寻常,因为我将默认超时时间设置为15秒,但是在发出请求后几乎立即出现此响应。我也希望看到我的API中已发出请求的日志,但看不到任何日志(我正在使用AWS API Gateway)。
我想知道Excel是否被阻止发出网络请求,这在某些Windows计算机中是否是默认行为?有没有办法在VBA中检查它?另外,似乎VBA-Web将状态码范围概括为408
(https://github.com/VBA-tools/VBA-Web/blob/eb857f0dee739ff4a55cfae80b24b82418aee816/src/WebClient.cls#L345-L352),有人知道为什么会返回这些吗?