简体   繁体   中英

postman - post application/json data

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

Click on x-www-form-urlencoded tab and enter the body. Now you can receive the body using req.body in backend.

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.

惊人的POSTman的屏幕截图!

This may solve your problem. Did u try this in your main .js file?

  app.use(bodyParser.urlencoded({
     extended: true
  }));
  app.use(bodyParser.json());

只需在服务器文件中使用以下语法

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())

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM