我试图将json发布到快速服务器并在req.body.name上获取未定义。
配置如下所示:
var express = require('express');
var app = express();
app.configure(function(){
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
});
路线如下:
module.exports.start = function(){
app.get('/', function(req, res){
console.log("params: " + req.params);
res.send("got it");
});
app.post('/test', function(req, res){
console.log("Post test: " + req.body.name);//this is undefined
res.send(req.body);
});
app.set('port', process.env.Port || 3000);
app.listen(app.get('port'), function(){
if (process.env.NODE_ENV == 'production') {
console.log("listening on port: " + app.get('port'));
}
console.log("listening on port: " + app.get('port'));
});
}
答案 0 :(得分:0)