node.js - curl成功浏览器连接不上
高洛峰
高洛峰 2017-04-17 16:21:59
0
2
668

我在对着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,都无效)

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
迷茫

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

迷茫

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template