学习express之实现Json的Post请求
2015-09-08 00:00
543 查看
参考:http://yijiebuyi.com/blog/38f1437bf5b43fcf90e6529a81f258f1.html
参考:http://yijiebuyi.com/blog/90c1381bfe0efb94cf9df932147552be.html
1)引入模块body-parser
2)post方法
3)注意事项
**bodyParser模块,应放在路由之前
参考: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);
相关文章推荐
- XML 与 JSON 优劣对比
- 如何安装SQL Server 2008 Management Studio Express
- newtonsoft.json解析天气数据出错解决方法
- vbs 解析json jsonp的方法
- Extjs4如何处理后台json数据中日期和时间
- C#实现将类的内容写成JSON格式字符串的方法
- jquery JSON的解析方式示例介绍
- c#版json数据解析示例分享
- ASP JSON类文件的使用方法
- POST与GET方法的区别简要分析
- C#实现对Json字符串处理实例
- C#使用post发送和接收数据的方法
- C#实现Json转Unicode的方法
- VB使用XMLHTTP实现Post与Get的方法
- 分享下GET和POST的真正区别
- php采用ajax数据提交post与post常见方法总结
- php解析json数据实例
- ajax 的post方法实例(带循环)
- PHP6 先修班 JSON实例代码