我試圖讓一個循環與http.get請求 - 我不知道爲什麼函數不啓動。 我的代碼是:節點http.get沒有解僱
while(List.length>0) {
if(counter < Limit) { // Limit is the amount of requests I want to
counter++;
inProcess++;
var scanitem = List.pop();
var body = "";
var url = 'https://www.mywebsite.com/'+scanitem;
var options = {
path: url,
method: 'GET'
};
console.log(url); // This part is happenning
var _request = https.get(options, function (res) {
console.log('get web site');// this part is NOT showup.
res.on('data', function (chunk) {
console.log(chunk); // this part is NOT showup.
body += chunk.toString();
});
res.on("end", function() {
console.log(body);// this part is NOT showup.
});
res.on("error", function(error) {
console.log('error')// this part is NOT showup.
});
});
_request.end();
}
else {
console.log('list BREAK');} // This part is happenning after the limit crossed
您可以首先添加'_request.on(「error」,function(error)'來找出任何錯誤,因爲如果在發送任何響應之前請求本身可能失敗,則不會顯示響應錯誤。 – user568109
https請求可能因爲你沒有給任何服務器可能拒絕請求本身 – user568109