0
我想發佈http請求,直到收到正面響應。如果我的筆記本電腦上的wifi開啓,我會得到積極的迴應,程序退出(正確)。如果我的筆記本電腦上的wifi最初是關閉的,但在程序仍在嘗試時打開,我沒有得到積極的響應,程序一直嘗試失敗,直到它退出。 wifi打開時應該不會xmlhttp.status = 200?重新建立連接後xmlhttprequest狀態不會更改
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 XMLHTTPRequest returns status code 200 (OK) and the response text contains REPORT_SUCCESS, it means that 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) and the response text does not contain REPORT_SUCCESS
break;
} else {
//try again
}
}
}
WScript.Sleep(1000);
}
不知道我明白。我移動了語句xmlhttp.send(Base64.encode(data));在for循環中,它仍然無法工作。 – user2442193
如果再次嘗試 – comphilip
則使用循環中的新xmlhttp。這工作。謝謝 – user2442193