Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

node.js - nestjs substitutes symbols in request body

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.

question from:https://stackoverflow.com/questions/65951871/nestjs-substitutes-symbols-in-request-body

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...