var http = require(‘http’); var querystring = require(‘querystring’); var server = http.createServer(function(req, res) { var post = '’; req.on('data’, function(chunk) { post += chunk; }); req.on('end’, function() { post = querystring.parse(post); console.log(text); res.write(post.title); res.write(post.text); res.end(); }); }).listen(3000);
1、通过formidable模块开parse一下就可以获得post上来的数据 2、直接读取request下的socket读到的数据 var first = request.socket.ondata.arguments[0],//传入socket接收的buffer对象(slowbuffer) second = request.socket.ondata.arguments[1],//buffer对象偏移量(number) thrid = request.socket.ondata.arguments[2];//长度(number) if(request.method=="POST"){ var formdata = first.slice(second,thrid).toString().split(“\r\n\r\n”); var fields = querystring.parse(formdata[1]); } 这个是我使用的两种方法
@ggaaooppeenngg我是这样做的: if(request.method.toLowerCase() ==’post’) { var info=""; request.addListener("data",function(data) { info+=data; }); request.addListener("end",function() { console.log(info); username=querystring.parse(info).username; password=querystring.parse(info).password; //info=querystring.parse(info); //console.log(request.body.username); console.log(username); hand_mysql.checkLogin(username,password,response); }); }