var request = require('request'), async = require('async');
var opt=["http://localhost:8080/examples/jsp/abc.jsp","http://192.168.24.180:8080/examples/jsp/abc.jsp"];
function req()
{
var count = 0;
async.eachSeries(opt, function(entry, callback)
{
count++;
request(entry, function(error, response, body)
{
if (!error && response.statusCode == 200)
{
console.log('Yes ' + entry);
}
else
{
console.log('No '+entry);
}
callback();
});
}, function(err)
{
console.log('Continue');
});
}
req();
如果响应时间超过0.5秒,如何让它显示“否”。服务器上的文件具有随机休眠时间。
答案 0 :(得分:1)
您使用的是https://github.com/mikeal/request吗?
如果是这样,根据http://www.sitepoint.com/making-http-requests-in-node-js/,您可以传入一个对象进入[request(条目,函数(错误)而不仅仅是一个URL并包含在其中。
从站点点链接
request({
uri: "http://www.sitepoint.com",
method: "GET",
timeout: 10000, <- that's what you looking for
followRedirect: true,
maxRedirects: 10
}, function(error, response, body) {
console.log(body);
});