參考:http://yijiebuyi.com/blog/38f1437bf5b43fcf90e6529a81f258f1.html html
參考:http://yijiebuyi.com/blog/90c1381bfe0efb94cf9df932147552be.htmljava
1)引入模塊body-parserjson
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方法app
router.post('/group', function(req, res, next) { console.log('post group redpack'); console.log(req.headers['content-type']) res.send(req.body); });
3)注意事項post
**bodyParser模塊,應放在路由以前ui
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);