【发布时间】:2016-01-07 20:43:44
【问题描述】:
这是我用来从 URL 下载图像的代码:
http.get(options, function (res) {
res.on('data', function (data) {
file.write(data);
}).on('end', function () {
file.end();
console.log(file_name + ' downloaded ');
cb(null, file.path);
}).on('error', function (err) {
console.log("Got error: " + err.message);
cb(err, null);
});
});
如何为每个请求添加超时,使其不会一直等待大数据或无响应的响应?
【问题讨论】:
-
听起来是个好计划。你试过什么?
-
使用这个:nodejs.org/api/…
-
但是我应该如何在这里使用响应对象???