簡體   English   中英

NodeJS中POST請求的請求正文為空

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM