CNode

req.on(end,...)会执行两遍么?

WWeb-Kevin发布于12 年前最后回复12 年前2 回复7617 浏览0 收藏
var http=require('http');
var querystring = require('querystring');
var util = require('util');

http.createServer(function(req,res){
        var post='';

        req.on('data',function(chunk){
                post+=chunk;
        });
        req.on('end',function(){
                post=querystring.parse(post);
        //      console.log('......'+post)       1.
                res.end();
                console.log(post)              // 2
        });
}).listen(3000);

我写个post表单请求一次,但怎么打印两次post 1处打印两个相同字符{xxx:xxx} 2处打印字符为{xxx:xxx}{}

谁能解释一下

查看回复

回复 (2)

G
GuoZhang#1·12 年前

感觉是favicon捣的鬼。

http.createServer(function(req,res){
    conosle.log(req.url);   // 查看下请求的url
    // ...
}

看看是不是会出现/favicon.ico -- 如果出现的话,这是浏览器在访问首页的同时,还试图访问/favicon.ico来获取favicon。

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