node.jspipe道restify http客户端响应
我有这个确切的问题,除了我使用restify HttpClient:
node.js写入http响应stream
为了清楚起见,我试图做到这一点:
var client = restify.createClient({ url: "http://www.google.com" }); client.get("/", function(err,res) { res.pipe(process.stdout); });
它挂起几秒钟,但从不写入任何标准输出。 显然,我正在尝试获取比谷歌的主页,但例如…
我会build议你的用户请求这样的事情:
var request = require('request'); // npm install request request('http://www.google.com').pipe(process.stdout);
看看restify的文档 ,似乎你需要等待“结果”事件:
var client = restify.createClient({ url: "http://www.google.com" }); client.get("/", function(err,req) { req.on('result',function(err2,res) { res.pipe(process.stdout); res.on('end',function() { process.exit(0); }); }); });