![](/img/trans.png)
[英]Why does Node.js on http-server freeze when you enter url parameter
[英]Why does node.js, http-server, show that there are two request coming?
我使用node.js进行了以下简单的http服务器设置:
var http = require('http');
var port = 12311
http.createServer(function (req, res) {
console.log("Incomming request from " + req.connection.remoteAddress);
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end("test string");
}).listen(port);
console.log("Listening on " + port);
如您所见,当有请求传入时,我将其登录到控制台。 现在,当我浏览到localhost:12311
,控制台显示localhost:12311
了两个连接:
"E:\Program Files\nodejs\node.exe" hello-world-server.js
Listening on 12311
Incomming request from 127.0.0.1
Incomming request from 127.0.0.1
为什么是这样?
通常是对favicon.ico
的请求。 即使您没有,也需要它,因为如果未在标题中设置相关的<link rel="shortcut icon"...
,则该规范将定义默认文件路径。
查找请求的最佳方法是:
req.url
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.