我正在尝试使用Express JS为应用创建基本的登录脚本,并且一直在进行POST功能来为我执行相同的任务。但是,每当我尝试回显所传递的参数(通过Postman测试脚本)时,这些值始终是不确定的。
将感谢您的帮助!谢谢:)
代码:
-d
正在传递JSON:
const express = require('express'),
app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/',(request,response)=>{
response.send('This is a test message');
});
app.post('/login', (request,response)=>{
let uname = request.body.username;
let pword = request.body.password;
response.send('Username: ' + uname + ' and Password: ' + pword);
});
//Binding the server to a port(3001)
app.listen(3001, () => console.log('express server started at port 3001'));