请求正文在nodejs中对于发布请求是空的
我有下面的代码,当我通过邮递员发送Post请求时,我得到的请求是未定义的
发布请求是http:// localhost:1702 / es
身体:
{“ip_a”:“191.XXXX”,“pkts”:34
}
和Content-Type:“application / json”我也使用了application / x-www-form-urlencoded,但得到了相同的结果。
我的app.js是
var express = require('express'); var es=require('./routes/es'); var app = express(); app.post('/es',es.postesdata); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true }));
而我的文件,我收到一个请求身体null是
exports.postesdata=function(req,res){ var body=req.body; console.log(body);//Getting Undefined here }
我在这里做错了吗?
express
运行中间件为了试试:
app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.post('/es',es.postesdata);