0

I'm trying to send a request to my Nestjs application, with just plain string in the request body, for example:

test23+Se5+345

Then in my application, I have a middleware, where I need to do something with this string. The problem is when I access request body in middleware const requestBody = Object.keys(req.body)[0];, this string looks like this:

test23 Se5 345

All of the + symbols are substituted by

I don't have additional convertings before this, and I know that middleware runs first in the request lifecycle. I think maybe there is some issue with body-parser, but I don't know yet how to fix this.

1 Answers1

0

This is because symbol + is treated as space, so before send it, you need to encode your + characters to %2b. More here: How to encode the plus (+) symbol in a URL

cojack
  • 2,444
  • 1
  • 17
  • 18