Post request body is empty with the content-type application/json.

4,664 views
Skip to first unread message

Ajay

unread,
Nov 8, 2016, 1:04:07 AM11/8/16
to Express
Here is the code I got from the express api examples in the express web site.  I am not sure what is exactly wrong, as this is an example of the official express site. This is the http request I submitted via fidler. Any idea what is being implemented in-correctly

content-type : application/json;charset=utf-8
Host: localhost:3000
Content-Length: 30

{"DataPacket" : [100,200,300]}


var app = require('express')();
var bodyParser = require('body-parser');
var multer = require('multer'); // v1.0.5
var upload = multer(); // for parsing multipart/form-data

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded

app.post('/profile', upload.array(), function (req, res, next) {
  console.log(req.body);
  res.json(req.body);
});

app.listen(3000, function() {
  console.log("listening Port to 3000.")
}

Thanks,
Ajay.

Ajay

unread,
Nov 8, 2016, 12:07:27 PM11/8/16
to Express
Sorry this work for me now. However this works via PostMan, but not thru' fidler, not sure what is going on? So this is a non issue.

Thanks,
Ajay.

O haya

unread,
Nov 10, 2016, 11:39:50 AM11/10/16
to Express
Hi,

I'm still new to Node.JS/Express, but I am/was running across something similar, and I *think* that my problem was that the HTTP client I was using was inserting a Content-Type header that was causing Express to not recognize the request/message.

In other words, when you configure the bodyParser, I think it looks for a specific Content-Type HTTP header in the request, and if the Content-Type is different/wrong or missing, then the bodyParser will ignore it.

So maybe that's why you're seeing it work with one client and not work with a different type of client?

Jim
Reply all
Reply to author
Forward
0 new messages