0

What I need

  • Ability to hit an endpoint on my webserver multiple times in a single call to my sub
  • Each http call is done asynchronously.
  • Each http call is done with no caching / no cache busting workarounds which fill my cache.
  • Each http calls is not slowed down much compared to a normal http call.

What I have tried

Given caching issues with MSXML2.XMLHTTP60 and issues with MSXML2.ServerXMLHTTP on corporate networks, I am using WinHttp.WinHttpRequest.5.1.

I have this code:

Sub winhttp_test()
    Dim http As Object
    Set http = CreateObject("WinHttp.WinHttpRequest.5.1")

    http.Open "GET", "http://localhost:6969/test/winhttp_1", True
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.setRequestHeader "Cache-Control", "max-age=0"
    http.send

    'Set http = CreateObject("WinHttp.WinHttpRequest.5.1")

    http.Open "GET", "http://localhost:6969/test/winhttp_2", True
    http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    http.setRequestHeader "Cache-Control", "max-age=0"
    http.send
    MsgBox "done"
End Sub

My server never sees the first request (even if I uncomment the commented line).
If I remove the MsgBox call, then my server sees neither request. It's like the send won't work if the object is destroyed straight after the call.

If I use ServerXMLHTTP on a machine with no network issues, I get the same issue.

(note: /test is the path to the end point. So both calls are hitting the same endpoint but with a different parameter the the url. I've tried instead to use GET and POST paramters, but the issue remains the same).

How do I achieve the behaviour I need?

Griffin
  • 13,184
  • 4
  • 29
  • 43
  • https://stagesolutions.wordpress.com/2012/04/18/asynchronous-download-from-http-with-vba/ – Tim Williams Mar 22 '21 at 16:16
  • Allocate a global `VBA.Collection` and make sure to `Add` your `http` instances to it immediately after each `CreateObject` call. This way these COM objects are not going to be deallocated when going out of scope at routine end which in your case closes the request socket prematurely and it never reaches the target host. – wqw Nov 09 '21 at 18:03

0 Answers0