2

I send this request with postman.

postman

And I console.log(req.body) returns an array like this:

{ '{"urls":["https://example.com?paramOne': 'foo',
  paramTwo: 'bar"]}' }

How can I get the whole body as a simple string like this?

{"urls":["https://example.com?paramOne=foo&paramTwo=bar"]}
1
  • try pm.request.body.raw Jun 18, 2018 at 13:08

1 Answer 1

7

In app.js: Replace:

app.use(express.json());

With:

var rawBodySaver = function (req, res, buf, encoding) {
  if (buf && buf.length) {
    req.rawBody = buf.toString(encoding || 'utf8');
  }
}

app.use(bodyParser.json({ verify: rawBodySaver }));
app.use(bodyParser.urlencoded({ verify: rawBodySaver, extended: true }));
app.use(bodyParser.raw({ verify: rawBodySaver, type: '*/*' }));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.