节点:发送一次请求,但得到两个输出?
Node: Sending a request once, but getting two outputs?
const http = require('http')
const server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/plain')
console.log('Incoming')
res.write("Hello world, request granted!")
res.end()
})
server.listen(3000, 'localhost', () => {
console.log("Listening for requests on port 3000")
})
每当我启动服务器时,它都会显示“正在侦听端口 3000 上的请求”,这是正确的。但是当我在 Chrome 上打开 localhost:3000 时,它显示了两次“传入”。为什么是两次? :D 我不明白。
默认情况下,所有浏览器都会尝试从每个站点获取 favicon.png
。这就是为什么您看到有两个请求发送到您的服务器。
如果您使用 postman 或 curl 发送请求,您将只会看到一个请求。
提示:打开浏览器控制台上的网络选项卡,您会看到对网站图标的请求。
const http = require('http')
const server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/plain')
console.log('Incoming')
res.write("Hello world, request granted!")
res.end()
})
server.listen(3000, 'localhost', () => {
console.log("Listening for requests on port 3000")
})
每当我启动服务器时,它都会显示“正在侦听端口 3000 上的请求”,这是正确的。但是当我在 Chrome 上打开 localhost:3000 时,它显示了两次“传入”。为什么是两次? :D 我不明白。
默认情况下,所有浏览器都会尝试从每个站点获取 favicon.png
。这就是为什么您看到有两个请求发送到您的服务器。
如果您使用 postman 或 curl 发送请求,您将只会看到一个请求。
提示:打开浏览器控制台上的网络选项卡,您会看到对网站图标的请求。