11
Is there any relevant difference between content-type
x-www-form-urlencoded
and form-data
?
I always have doubts when I should use between one or the other, because I don’t know if there is any striking difference.
11
Is there any relevant difference between content-type
x-www-form-urlencoded
and form-data
?
I always have doubts when I should use between one or the other, because I don’t know if there is any striking difference.
21
These content-type specifies how the form data should be encoded when sent to the server (only when method="post")
To application/x-www-form-urlencoded
, the body of the HTTP message sent to the server is essentially a query string, name / value are separated by the commercial (&), and the names are separated from the values using equal (=). An example of this would be:
Name=rafael&city=campinas&idade=31
This means that for every non-alphanumeric byte that exists in one of our values, it will take three bytes to represent it. For large binary files, tripling the load will be highly inefficient.
That’s where multipart/form-data
enters. With this name/value pairing method, each pair is represented as a "part" in a MIME message (as described by other responses). The pieces are separated by a particular sequence (chosen specifically so that this chain does not occur in any of the "value").
Each part has its own set of MIME headers as Content-Type, and particularly Content-Disposition, which can give each party its "name". The value of each piece of name / value pair is the payload of each part of the MIME message.
The MIME specification gives us more options when representing the value of the payload - we can choose a more efficient binary data encoding to save bandwidth (for example base 64 or even simple binary).
Why not use Multipart / form-date all the time? For short alphanumeric values (like most web forms), the overload of adding all MIME headers will significantly exceed any more efficient binary encoding savings.
The moral of the story is, if you have binary (non-alphanumeric) data (or a load size significantly) to transmit, use Multipart / form-data. Otherwise, use application / x-www-form-urlencoded.
source: https://gist.github.com/joyrexus/524c7e811e4abf9afe56
Browser other questions tagged http http-headers
You are not signed in. Login or sign up in order to post.
@Edilson only explains one thing to me: that
form-data
that appears in Postman is the same thing asmultipart/formdata
? If so, I will delete the question . kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk– Wallace Maxters
What is Postman ?
– Edilson