我需要关于 node.js 的帮助:我的 req.body 是这样填充的
{
'{
"email":"mail@hostname.com",
"password":"12345"
}'
: ''
}
但我无法获取值 req.body.email 和 req.body.password 未定义
我的代码是:
user.js
exports.loginByEmail= function(req, res) {
console.log('POST');
console.log(req.body);//show values
console.log(req.body.email);//undefined
console.log(req.body.password);//undefined
User.find({email:req.body.email,password:req.body.password}).toArray(function(err, userLoged) {
if(err) return res.send(500, err.message);
res.status(200).jsonp(userLoged);
});
};
app.js
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
methodOverride = require("method-override");
mongoose = require('mongoose');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride());