bodyParser.json with custom type application/*+json return an empty body
See original GitHub issueI’m developing a HTTP server to interface with oneM2M. The header of the POST request received by oneM2M are:
content-type: 'application/vnd.onem2m-ntfy+json'
content-length: 441
Here the HTTP server code:
var express = require('express');
var bodyParser = require('body-parser');
var port = 3331;
var app = express();
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json({
type:'application/vnd.onem2m-ntfy+json'
}));
app.listen(port);
console.log('SERVER LISTENING ON PORT ' + port);
console.log();
app.post('/', function(req, res) {
console.log("REQUEST");
console.log(req.body);
console.log();
res.status(200).send('OK');
});
The received body is empty. It is strange because in the request POST header content-length is not 0 and content-type defined for the bodyParser is the same in the POST header! Could you help me to solve this issue?
Kind regards, Luca
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
req.body empty on posts - node.js
You have to check whether the body-parser middleware is set properly to the type of request(json, urlencoded). If you have set, app.use(bodyParser.json());.
Read more >Express body-parser middleware
Returns middleware that only parses json and only looks at requests where the Content-Type header matches the type option. This parser accepts any...
Read more >req.body gets populated to empty object even when it ...
Expected behaviour. If the body was not parsed by some other parser before bodyParser.json , and if the current request is NOT to...
Read more >req.body is empty in POST requests : r/node
I noticed that POST requests on my node server were not functioning properly (ie: not returning the expected data) so I tried a...
Read more >Scala Body Parsers - 2.8.x
We can use any Scala type as the request body, for example String , NodeSeq , Array[Byte] , JsonValue , or java.io.File ,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Too old version
P.S. if you’re using Express 4.16.0+ you don’t even need to require the
body-parser
separately, since it’s included now: