CNode

求助,get请求为什么发出了两次

Jjtyjty99999发布于14 年前最后回复14 年前8 回复7585 浏览0 收藏
var http = require('http'),
q = require('querystring');

http.createServer(function (req, res) {

		var options = {
			host : '192.168.1.2',
			port : 7379,
			path : '/INCR/soscount',
			method : 'get'
		};

	//服务端发出请求get
	http.get(options,function(response){
		res.writeHead(200, {'Content-Type': 'text/plain'});
		var pageData = "";
		response.setEncoding('utf8');
		//接受数据,保存
		response.on('data', function (chunk) {
		  pageData += chunk;
		});

		//数据接收完毕, 输出到客户端
		response.on('end', function(){
		  res.write(pageData);
		  res.end();
		});

	});

}).listen(4000);
console.log("httpServer is listening at port 4000")

想用nodejs发起一个webredis的测试, 直接浏览器访问 http://192.168.1.2:7379/INCR/soscount 的时候 每次访问 数字会+1 但是如果通过nodejs 访问,每次访问数字会+2 这是为什么呢。。。

查看回复

回复 (8)

C
clamingo#1·14 年前

因为多访问了一次"/favicon.ico"

J
jtyjty99999#2·14 年前
引用 clamingo因为多访问了一次"/favicon.ico"

明白了,要路由一下,感谢

A
a272121742#3·14 年前
引用 clamingo因为多访问了一次"/favicon.ico"

@clamingo 跪求麻烦给我补充一点知识 1.为什么会多一次/favicon.ico 2.这个请求是所有浏览器都默认请求的还是个别现象 3.这样的2次请求能通过设置修改为一次吗?

L
leizongmin#4·14 年前
引用 clamingo因为多访问了一次"/favicon.ico"

@a272121742 1、请求/favicon.ico是用于显示网站的图标,如右图:enter image description here 2、大多数浏览器都会发出这样的请求,算是“默认”的吧 3、只要你返回一个有效的的/favicon.ico文件,并且指定expire时间,相信浏览器不会每次都重新发出请求的。

L
leizongmin#5·14 年前
引用 clamingo因为多访问了一次"/favicon.ico"

@a272121742 connect中是专门有一个中间件来处理这个问题的,参考这里:http://www.senchalabs.org/connect/favicon.html

A
a272121742#6·14 年前
引用 clamingo因为多访问了一次"/favicon.ico"

@leizongmin 拜读,言谢

C
clamingo#7·14 年前
引用 clamingo因为多访问了一次"/favicon.ico"

@jtyjty99999 如上所言。周末断网状态,不好意思。

J
jtyjty99999#8·14 年前
引用 clamingo因为多访问了一次"/favicon.ico"

@clamingo @leizongmin @a272121742 感谢你们的解答

参与回复
登录后即可参与回复。登录