【发布时间】:2016-12-22 07:04:33
【问题描述】:
我设置了一个快速应用程序。
我已经定义了我的路线,
var ctrlLocations = require('../controllers/locations');
router.post('/locations', ctrlLocations.locationsCreate);
module.exports = router;
这里是locations.js文件,
module.exports.locationsCreate = function(req, res){
console.log(req.body.name);
}
当我使用 Postman 发送发布请求时,如果我将正文作为 x-www-form-urlencoded 发送,则一切正常,并且我会看到我定义的“名称”。
但是,当我将正文作为表单数据发送发布请求时,我得到“未定义”
是的,我正在使用 body-parser
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
【问题讨论】:
-
可以添加表单代码吗?您提交表单的方式和网址。
-
在
app.use(bodyParser.urlencoded({extended: true}));中设置extended: false并重试。
标签: javascript node.js http express