2

I have an Excel add-in built using VBA and one of my users is experiencing Request Timeouts when attempting to Post to my cloud-based API. I'm using VBA-Web tools https://github.com/VBA-tools/VBA-Web to make HTTP requests.

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

I've asked the user to send me their logs and they look like this:

Response.StatusCode
Response.StatusDescription

>> 408
>> Request Timeout: The operation timed out

I originally assumed this was a firewall issue because no one has reported this issue apart from one group of users (located within the same building), but I've asked them to navigate to the URL in their internet browser and they were able to get a response.

This is unusual since I've set the default timeout period to 15 seconds and yet this response appears almost immediately after making the request. I'd also expect to see logs from my API that a request was made but I can see none (I'm using AWS API Gateway).

I'm wondering whether Excel being blocked from making network requests, is this a default behaviour in some Windows machines? Is there a way to check for it within VBA? Also, it looks like VBA-Web generalises a range of status codes as 408 (https://github.com/VBA-tools/VBA-Web/blob/eb857f0dee739ff4a55cfae80b24b82418aee816/src/WebClient.cls#L345-L352), is anyone familiar with why these would be returned?

2
  • What method are you using to send the Request? Are you launching a browser in the background or using XmlHttpRequest? It would be helpful if you shared the code of your send function. Commented Nov 5, 2019 at 10:54
  • I'm relying on VBA-Web, which is using WinHttpRequest.5.1 Commented Nov 5, 2019 at 11:01

1 Answer 1

1

Try to change library.

I've dealt with many API services and, from my experience, if it works on the browser it has almost certainly to do with the library you use and how it handles the request, which in this case is WinHttpRequest 5.1.

I would suggest using an alternative library to send your data and see if that works, like MSXML2.XMLHTTP60. In this example, you send a GET request (useful to see if you can reach the server):

Sub tester()
Dim objCON As New MSXML2.XMLHTTP60
Dim URL As String

    URL = "http://www.myurl.com"

    objCON.Open "GET", URL, False
    objCON.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    objCON.send 

    MsgBox (objCON.responseText)
End Sub

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Louis, after checking the users version it seems they are using a 64-bit version of Excel and it seems that others using 64-bit are having similar issues and recommend the same solution (github.com/VBA-tools/VBA-Web/issues/389). I'm going to try and replicate the issue using a 64-bit Excel and see if MSXML2.XMLHTTP60 works.
You're welcome @bgordon. Let us know if it solved the issue in the end!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.