How can I send application/json data through postman, so that i can recieve the same data in nodejs server as req.body. I have tried raw body json in postman which sends the data as application/json, but data is available in server as req.rawBody. I need to get the same in req.body. Is there any such option
-
1Have you set the `Content-Type` header to `application/json?` – chrisbajorin Apr 03 '15 at 13:53
-
Also be sure to use body-parser – Yousef Apr 03 '15 at 16:47
-
1yes i tried both. but no result – Riyas TK Apr 05 '15 at 06:53
-
Please see the below link https://stackoverflow.com/questions/41955103/cant-get-post-data-using-nodejs-expressjs-and-postman/53514520#53514520 It will help you – Goutam Ghosh Dec 03 '18 at 11:04
5 Answers
Click on x-www-form-urlencoded tab and enter the body. Now you can receive the body using req.body
in backend.
-
1but here the data is send as x-www-form-urlencoded form. I need the data to be send as application/json – Riyas TK Apr 03 '15 at 12:09
First, you must choose an http method that supports a body like "POST", "PUT", or "PATCH". Because "GET" and "DELETE" don't support a body.
Then you choose a data type of "raw" and paste/type your JSON data.

- 6,851
- 3
- 50
- 88
This may solve your problem. Did u try this in your main .js file?
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());

- 1
- 1
Simply use following syntax in server file
const bodyParser = require('body-parser') const cors = require('cors'); app.use(cors()) // for crossOrigin Access
app.use(bodyParser.urlencoded({extended: false})) app.use(bodyParser.json())

- 589
- 6
- 16
If you want to send files with a json you can use the multiform-data in postman. use multer npm extension to get the files and use JSON.parse(request.body) to pars the json and access its fields.

- 777
- 1
- 8
- 19