【发布时间】:2019-05-10 02:31:48
【问题描述】:
这是我第一次使用 node js。我正在通过 Postman 发送邮寄请求。问题是我无法获得这些参数。它说未定义或为空
这是我迄今为止尝试过的
var express = require("express");
var app = express();
var bodyParser = require('body-parser')
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
// support encoded bodies
app.listen(3000, () => {
console.log("Server running on port 3000");
});
app.post('/login',function(req,res){
console.log('request =' + JSON.stringify(req.body))
console.log(req.body);
var user_name=req.body.user;
var password=req.body.password;
res.send(req.body);
console.log("User name = "+user_name+", password is "+password);
res.end("yes");
});
express 版本是 4.16.4
这是显示在控制台上的内容
【问题讨论】:
-
你能添加你的控制台日志吗
-
您是否将 'application/json' 作为内容类型标头发送?
-
你用的是什么版本的 Postman,好像很老了。
-
@NirLevy 我已经更新了我的问题
-
@BraveButter 我在我的问题中添加了控制台日志
标签: node.js express postman postman-pre-request-script