跳到正文
当下的七炎
返回

express post请求res.body 取不到数据

编辑文章

使用post请求,json格式的时候,req.body=undefind 这里需要使用一个中间件body-parser

var express = require('express');
var bodyParser = require('body-parser');

var app = express();

// see https://github.com/expressjs/body-parser
// 添加 body-parser 中间件就可以了
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());

app.post('/', function (req, res) {
    console.log('req.body', req.body);
    res.send({airead: 'fan'});
});

app.listen(8888);

参考链接 https://cnodejs.org/topic/53c89067c9507b4044b1deaa https://github.com/expressjs/body-parser


编辑文章
分享这篇文章:

评论

使用 GitHub 账号登录后即可评论


上一篇
node+Mongoose实现分页
下一篇
数组去重