参考:http://yijiebuyi.com/blog/38f1437bf5b43fcf90e6529a81f258f1.html
参考:http://yijiebuyi.com/blog/90c1381bfe0efb94cf9df932147552be.html
1)引入模块body-parser
var bodyParser = require(‘body-parser‘);
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: false}));
// parse application/json
app.use(bodyParser.json());
2)post方法
router.post(‘/group‘, function(req, res, next) {
console.log(‘post group redpack‘);
console.log(req.headers[‘content-type‘])
res.send(req.body);
});
3)注意事项
**bodyParser模块,应放在路由之前
var bodyParser = require(‘body-parser‘);
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: false}));
// parse application/json
app.use(bodyParser.json());
...
app.use(‘/‘, routes);
app.use(‘/app‘, apps);
原文:http://my.oschina.net/u/2351685/blog/502797