首页 新闻 赞助 找找看

node.js默认的请求/favicon.ico

0
[待解决问题]

每个页面默认都会再发一个/favicon.ico
var http=require('http');
var i=0;
var req=function(req,res){
i=i+1;
console.log(i,req.url);
res.writeHead(200,{'Content-Type':'text/plain'});
res.end('Hello World\n');
};

http.createServer(req).listen(8888,"127.0.0.1");
console.log('Server running...');##控制台输出:
Server running...
1'/'
2'/favicon.ico'


因为自己也遇到了这个问题,但是网上的这个输出好像是错的,我实际运行了一下,第一次输出是下面
Server running...
1'/favicon.ico'
2'/'
3'/favicon.ico'

当你刷新一次页面的时候才是两次
4'/'
5'/favicon.ico'
也就是说第一访问发了三次请求,但是从代码来看应该是一个url(/favicon.ico)不是吗为什么第一次会发了三次呢?

下面是我自己写的代码确实是两次
var http=require('http');

http.createServer(function(request,response){
response.writeHead(200,{'Content-type':'text/html;charset=utf-8'});
if(request.url!=="/favcon.ico"){
console.log(request.url);
response.end('');
}
}).listen(8000);


求大神帮忙解答!!!

何以风叶的主页 何以风叶 | 菜鸟二级 | 园豆:202
提问于:2016-12-16 20:18
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册