body-parser不会填充req.body

时间:2016-08-04 07:43:55

标签: javascript node.js express body-parser

我使用express 4.14和body-parser模块。 req.body obj没有填充。如在类似问题的答案中指出的那样,绑定的顺序是正确的。

app.js

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var engine = require('ejs-locals');

var app = express();
var index = require('./routes/index');

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.engine('ejs',engine);

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', index);
app.use('/authme', index);

module.exports = app;

index.js

var express = require('express');
var router = express.Router();

router.get('/authme',function(req,res,next){
        console.log(req.body);
        var userIdEntered = req.param("useridip2");

});
module.exports = router;

req.body是空的。

0 个答案:

没有答案