1/req.query:
Get:/domo?name=ximiximi&blog=https://home.cnblogs.com/u/ximiximi-blog/ app.get('/domo', function(req, res) { console.log(req.query.name); console.log(req.query.blog);});
2/req.body:
var bodyParser = require('body-parser'); app.post('/domo', function(req, res) { console.log(req.query.name); console.log(req.body.blog); });
tips:req.body是POST方法。需要注意的是需要npm body-parser
3/req.params:
app.get('/hello/:name/:blog', function(req, res) { console.log(req.params.name); console.log(req.params.blog);});
取带冒号的参数
借用他人对此req方法的理解,标注了出处:
(顺带补充,还有另一种方法传递参数给 Server,就是使用路径的方式,可以利用 Web Server 的 HTTP Routing 來解析,常见于各种 Web Framework。這不算是传统标准规范的做法,是属于 HTTP Routing 的延伸应用。http://liuxufei.com/blog/jishu/798.html)