0

这是我第一次使用节点 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");
});

快递版本是 4.16.4

这是控制台上显示的内容

在此处输入图像描述 在此处输入图像描述

4

1 回答 1

1

设置标题:{"Content-Type": "application/json"} 在请求中。改变它会解决问题。

于 2019-05-09T18:31:48.057 回答