我试图用 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