【发布时间】:2013-07-03 20:40:48
【问题描述】:
我尝试使用 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)找出任何错误。因为如果在发送任何响应之前请求本身可能失败,则不会出现响应错误。 -
https 请求可能需要密钥或证书。由于您没有给任何服务器可能会拒绝请求本身。
标签: node.js httprequest