Here is my code:
var
xhttp: OleVariant;
xhttp := CreateOleObject('MSXML2.XMLHTTP');
xhttp.Open('GET', URL, True);
xhttp.send();
while xhttp.readyState <> 4 do
begin
Application.HandleMessage;
end;
// status property is available only when readyState is complete
if (xhttp.Status = 200) then...
// do something
In this situation I do not want to use the event onreadystatechange.
The Question:
Is it safe to poll on the readyState for a value of 4, after I call Send, or is there a risk to be stuck in an endless loop?
Some facts:
The ServerXMLHTTPRequest can use a waitForResponse inside the loop, but I want to use XMLHTTPRequest component.
It is stated there that:
The waitForResponse method is more efficient than polling the
readyState property, which is the only way to wait for an asynchronous
send using the XMLHTTP component.
If you are worried about an endless loop, then simply implement a timeout for your loop, eg: