【发布时间】:2021-02-13 10:37:38
【问题描述】:
如果我在节点中编写以下程序:
http.createServer(function (req, res) {
if( req.method == 'GET' ) {
var body = ''; req.on('data', function(data) { body += data });
req.on('end', function() {
console.log('request ended')
});
}
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('142\n');
}).listen(3500);
然后用http://xxx.xx.xxx.xx:35010 访问服务器,我在控制台上看到request ended 两次——我不确定为什么单个HTTP 请求会导致它执行两次。
【问题讨论】:
-
@Jessemon 如果问题是重复的,请投票关闭作为重复而不是编辑问题。
标签: node.js