I need to continuously send an http request until I receive a positive response. When the wifi on my laptop is active, the program exits successfully. However, if the wifi is turned on while the program is still attempting, I do not get the desired response and the program keeps retrying until it eventually exits. Shouldn't the xmlhttp.status be 200 when the wifi is activated?
xmlhttp = new XMLHTTPRequest();
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader('User-Agent', 'XMLHTTP/1.0');
data = "Some text here";
xmlhttp.send(Base64.encode(data));
var timeout = 16;
var response = '';
for (var t = 0; t < timeout; t++) {
if (xmlhttp.ReadyState == 4) {
// If the XMLHTTPRequest returns status code 200 (OK) and the response text contains REPORT_SUCCESS, then the report was successful.
if (xmlhttp.Status == 200 && xmlhttp.ResponseText.indexOf(REPORT_SUCCESS) != -1) {
return true;
} else {
if (xmlhttp.Status == 200) {
// if the XMLHTTPRequest returns status code 200 (ok) but the response text does not contain REPORT_SUCCESS
break;
} else {
//try again
}
}
}
WScript.Sleep(1000);
}