What is "URL-encoded" Form data?

Hello, I know form data is just data when we submit a form but can someone explain what do we mean by "URL-encoded" form data please, why "encoded" ? I know we have 2 encoding, the URL-encoded thing and the multipart-formdata. How does these 2 differ?
18 Replies
ἔρως
ἔρως2w ago
when you send a form with the GET method, it goes all into the url url-encoded post is the same - except it goes in the body of the request and not in the url by the way, that's the default and it can't be used to send files
Jochem
Jochem2w ago
encoding is a way to take data from one format to another in a predictable, reproduceable way. In the context of URL encoding, it's taking characters that have meanings in a URL that could break the data up (like a /) and replacing them with placeholders (%2F off the top of my head) another way encoding is used is to take binary data and translate it into text. Usually that's done with utf-8 now, but in the past ISO-8859 was pretty popular too, and there's others too (like UTF-16) ASCII is a form of encoding too, saying that binary 65 is an A and 66 is a B for example the exact details of how URL and multipart encoding differ isn't really important though. Their purpose is to take data and transfer it to a format that's safe to transmit over the chosen protocol, in such a way that it can be turned back into the original data on the other side
ἔρως
ἔρως2w ago
one VERY VERY important detail is that url encoded forms cannot send files
Jochem
Jochem2w ago
Yeah, it's limited to utf characters I think
ἔρως
ἔρως2w ago
yup, utf8 is the only allowed encoding for webpages
Faker
FakerOP2w ago
yeah I see normally in a form, we have the multipart/form-data encytype and application/x-www-form-urlencoded (I think their is one more but let's consider only these 2). By default, our HTML form uses application/x-www-form-urlencoded. Normally, when we send a GET request, the parameters/input values go into the url, special characters like a space is encoded using %20 I think. So the encoding type is just how to represent characters to make both client/servers understand things? www-form-urlencoded can only encode text so that at the other end when it is being send to the server, we can parse it? On the other hand, using multipart/form-data, we can encode images etc?
Jochem
Jochem2w ago
pretty much
ἔρως
ἔρως2w ago
the way the request is built is very different too but that's getting into the weeds
Jochem
Jochem2w ago
yeah, more than I've ever worried about it at least all you really need to do is use method="GET" only when you really know you need it, and all the rest is POST
ἔρως
ἔρως2w ago
exactly by the way, you can use url parameters with a post request, regardless of the encoding that's something people forget
13eck
13eck2w ago
Think of x-www-form-urlencoded like a basic key/value pair. Like a JS object that can only have string keys and values, so no nested anything. Text only. No image, no video, no audio, no nothing. name=13eck&has-coffee=true&age=42 Very simple. Very easy to parse and read. multipart/form-data, on the other hand, is more complex as it's designed for transfering binary files. Audio, video, apps, pics, etc. Pretty much anything that's not sending raw text. While it can be used to send simple key/value pairs it's way overkill—like driving a Ferrari in bumper-to-bumper traffic. Have a looksie here for simple examples of both: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/POST#url-encoded_form_submission
Faker
FakerOP2w ago
yep noted, thanks ! oh ok, like query params can be used irrespective of the HTTP verb used, not just GET?
Jochem
Jochem2w ago
you can put query parameters in the action attribute if you want to that's what he's suggesting
13eck
13eck2w ago
query params are part of the URL. Anything that has a URL by definition can have query params
ἔρως
ἔρως2w ago
^ this and query parameters are url-encoded
13eck
13eck2w ago
url-encoded is written like query params, but are not query params
ἔρως
ἔρως2w ago
exactly
Faker
FakerOP2w ago
yep noted thanks !

Did you find this page helpful?