Reputation: 9538
I have a code in which I declared a variable like that
Dim http As New XMLHTTP60
then in the code, I used this line
http.Open "POST", urlexample, False
http.Send strArg
How can I use the waitForResponse
to wait for the server to respond to the request. I tried looping like that after the .Send
statement
While http.ReadyState <> 4: DoEvents: Wend
But this works sometimes well and sometimes doesn't return anything.
Upvotes: 0
Views: 1438
Reputation: 84465
Looking through object model seems that this method is not available through MSXML2.XMLHTTP60
but is with WinHttp.WinHttpRequest
. The latter does not have a ReadyState
property however.
You'll need to investigate the default timeout and see if you need SetTimeOuts on WinHttp object to obtain longer times.
Option Explicit
Public Sub testing()
Dim http As winHttp.WinHttpRequest
Set http = New winHttp.WinHttpRequest
With http
'.SetTimeouts ........
.Open "GET", "http://books.toscrape.com/", True
.setRequestHeader "User-Agent", "Mozilla/5.0"
.send
.waitForResponse 1000
End With
Stop
End Sub
N.B. Your request will not be async if the async arg is set to FALSE in the .Open
Interesting reading: https://github.com/VBA-tools/VBA-Web/issues/337
Seems Tim Hall's VBA-Web would be a nice pre-packaged way to go about this.
Upvotes: 1