cli*_*int 1 rest node.js express postman
我的路由文件中有以下代码:
router.post('/submit', function(req, res) {
var email = req.body.email;
console.log(email);
});
Run Code Online (Sandbox Code Playgroud)
我正在从邮递员那里拨打电话,并提供以下详细信息: http://localhost:3000/login/submit
参数:
email=abcxyz@gmail.com
Run Code Online (Sandbox Code Playgroud)
和标题我都试过了
Content-Type:application/json
Run Code Online (Sandbox Code Playgroud)
和
Content-Type: application/x-www-form-urlencoded
Run Code Online (Sandbox Code Playgroud)
另外,我在 app.js 中单独安装了正文解析器,并带有以下内容
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
Run Code Online (Sandbox Code Playgroud)
但是,电子邮件的控制台日志显示“未定义”。为什么我无法使用 req.body.email 获取帖子参数。
就我而言
router.post('/submit', function(req, res) {
console.log("Your Email is "+req.body.email);
res.end(); // if you not end the response it will hanging...
Run Code Online (Sandbox Code Playgroud)
仅设置您的标题类型
Content-Type application/x-www-form-urlencoded
Run Code Online (Sandbox Code Playgroud)
身体
| 归档时间: |
|
| 查看次数: |
3864 次 |
| 最近记录: |