I have the following simple http-server setup using node.js:
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);
As you can see, when a request comes in, I log it to the console. Now when I browse to localhost:12311
the console shows that two connections have come in:
"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
Why is this?
It's usually the request for the favicon.ico
. Even if you don't have one, it's requested as the norm defines a default file path if you don't set the relevant <link rel="shortcut icon"...
in the header.
The best ways to find about the requests are :
req.url
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.