search

Home  >  Q&A  >  body text

node.js - curl成功浏览器连接不上

我在对着Nodejs高级教程学习,有一节是向客户端传送子进程输出的例子。

var spawn=require('child_process').spawn;
require('http').createServer(function(req,res){
    var child=spawn('tail',['-f','/var/log/system.log']);
    child.stdout.pipe(res);
    res.on('end',function(){
        child.kill();
    });
}).listen(4007);

我是在windows系统中安装的babun,然后使用curl命令成功看到结果:


但是在服务器上打开就一直失败...

真心求教。。。强迫症的我一直在研究中.....
__
EDGE11和ff可以。。。不理解 chrome的安全机制吗(我有两个chrome,都无效)

高洛峰高洛峰2786 days ago669

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-17 16:23:59

    Didn’t you notice that curl never ends? This is not normal.

    The main reason is that your child process uses the tail -f command, so that the end time of res will not be triggered, and this request will never end.

    You can try using the cat command

    reply
    0
  • 迷茫

    迷茫2017-04-17 16:23:59

    You may be using fake chrome. . This is normal for me.

    But the only problem is that it keeps requesting data. . It should be that the tail command has not ended.

    reply
    0
  • Cancelreply