NodeJS Get/Post 参数获取
1. 获取Get请求中url的参数:
const urlib = require("url"); // http:///www.web.com/Login?name=111&pass=222 router.get('/Login', function(req, res, next) { var myObj = urlib.parse(req.url,true); var name = myObj.query.name; var pass = myObj.query.pass; console.log('name = ' + name + ', pass = ' + pass); // ... });
2. 获取Post请求的参数:
// http:///www.web.com/Login router.post('/Login', function(req, res, next) { var name = req.body.name; var pass = req.body.pass; console.log('name = ' + name + ', pass = ' + pass); // ... });