由于某种原因,我可以在我的路线上的快递服务器中看到我的req.body
req body is [Object: null prototype] { '{"password":"xxxxxxxx"}': '' }
但是当我登录req.body.password(对象键)时,我得到了
req body is undefined
这是我的Express应用中供我参考的索引路由器
var express = require('express');
var router = express.Router();
var bodyParser = require('body-parser')
const path = require('path');
/* GET adminPanel. */
router.post('/authenticate', function(req, res, next) {
console.log('req body is',req.body.password)
res.send("passconfirmed");
});
module.exports = router;
If you're using
body-parser
您必须先启用主体解析器,然后才能在路由中使用解析的数据。
在导入所有库的主模块中,需要声明express以使用body-parser中间件。
After including the
bodyparser middleware
you can use parsed data in your routes.