![](/img/trans.png)
[英]nodejs request returning null body from server for a POST request
[英]Request body is null for POST request in NodeJS
我有以下代碼。 當我通過 Postman 發出 Post 請求時,我得到req.body
未定義。
發布請求是http://localhost:1702/es
。
身體:
{
"ip_a":"191.X.X.XX",
"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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.