【发布时间】:2017-05-08 01:59:13
【问题描述】:
我的路由文件中有以下代码:
router.post('/submit', function(req, res) {
var email = req.body.email;
console.log(email);
});
我正在从邮递员那里拨打电话,详细信息如下: http://localhost:3000/login/submit
参数:
email=abcxyz@gmail.com
和标题我都试过了
Content-Type:application/json
和
Content-Type: application/x-www-form-urlencoded
另外,我在 app.js 中单独安装了正文解析器
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
但是,电子邮件的控制台日志显示“未定义”。为什么我无法使用 req.body.email 获取帖子参数。
【问题讨论】:
-
在body选项中你选择什么?表单数据、x-www-form-urlencoded、原始还是二进制?
-
你可以通过这个调用localhost:3000/login/submit来访问你的api吗?
-
您正在节点应用程序中为“/submit”创建一个发布路线,并尝试使用邮递员点击localhost:3000/login/submit。这是正确的吗?
标签: node.js rest express postman