Why do request parameters sent in request body need to be URL encoded?
Asked Answered
H

0

14

I understand with GET request they need to be entered into a URL and therefore need to be URL (percent) encoded so that they don't mean anything in the context of a server interpreting the URL.

But if data is in the body of a request rather than the URL then why does it need to be URL encoded?

Example:

enter image description here

Huckaback answered 25/11, 2017 at 19:33 Comment(6)
That request is sent with Content-Type: application/x-www-form-urlencoded which says "My body is url encoded" - so it must be url encoded. As to why the encoding is needed at all see https://mcmap.net/q/45139/-application-x-www-form-urlencoded-or-multipart-form-dataFlinger
If it's not url-encoded, you will not, in general, be able to uniquely parse the string into key-value pairs. Regardless of whether it's in the url (get) or in the body, the url-encoding ensures there is no ambiguity in understanding what has been sent.Duplicate
@AlexK. thanks for forwarding me that question, that one gives very good insight into what's actually happening.Huckaback
I have the exact same question. Did you find a definite answer?Bascio
@FlorianWalther the answer is that when we use POST, data is still submitted as a series of name=value pairs. Therefore we still need to url encode so that we can't have things like '=' or '&' in the value which will mes up the parsing of the values on the server. :)Huckaback
Thank you! That makes sense. No one really explains this anywhere, it's crazy.Bascio

© 2022 - 2024 — McMap. All rights reserved.