Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript node.js管道restify http客户端响应_Javascript_Node.js_Restify - Fatal编程技术网

Javascript node.js管道restify http客户端响应

Javascript node.js管道restify http客户端响应,javascript,node.js,restify,Javascript,Node.js,Restify,我有一个确切的问题,除了我使用的是restify HttpClient: 为了清楚起见,我尝试这样做: var client = restify.createClient({ url: "http://www.google.com" }); client.get("/", function(err,res) { res.pipe(process.stdout); }); 它会挂起几秒钟,但从未向stdout写入任何内容。显然,我正在尝试获取google主页以外的内容,但例如

我有一个确切的问题,除了我使用的是restify HttpClient:

为了清楚起见,我尝试这样做:

var client = restify.createClient({
    url: "http://www.google.com"
});

client.get("/", function(err,res) {
    res.pipe(process.stdout);
});

它会挂起几秒钟,但从未向stdout写入任何内容。显然,我正在尝试获取google主页以外的内容,但例如…

我会向用户推荐这样的内容:

var request = require('request'); // npm install request
request('http://www.google.com').pipe(process.stdout);

看起来你需要等待“结果”事件:

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);
    });
  });
});

你能在文档中引用它解释“结果”事件的地方吗?我没看见。但是谢谢,这很有效。