Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>TL;DR</strong></p> <p>Summary; if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use <code>multipart/form-data</code>. Otherwise, use <code>application/x-www-form-urlencoded</code>.</p> <hr> <p>The MIME types you mention are the two <code>Content-Type</code> headers for HTTP POST requests that user-agents (browsers) must support. The purpose of both of those types of requests is to send a list of name/value pairs to the server. Depending on the type and amount of data being transmitted, one of the methods will be more efficient than the other. To understand why, you have to look at what each is doing under the covers.</p> <p>For <code>application/x-www-form-urlencoded</code>, the body of the HTTP message sent to the server is essentially one giant query string -- name/value pairs are separated by the ampersand (<code>&amp;</code>), and names are separated from values by the equals symbol (<code>=</code>). An example of this would be:&nbsp;</p> <p><code>MyVariableOne=ValueOne&amp;MyVariableTwo=ValueTwo</code></p> <p>According to the <a href="http://www.w3.org/TR/html401/interact/forms.html" rel="noreferrer">specification</a>:</p> <blockquote> <p>[Reserved and] non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character</p> </blockquote> <p>That means that for each non-alphanumeric byte that exists in one of our values, it's going to take three bytes to represent it. For large binary files, tripling the payload is going to be highly inefficient.</p> <p>That's where <code>multipart/form-data</code> comes in. With this method of transmitting name/value pairs, each pair is represented as a "part" in a MIME message (as described by other answers). Parts are separated by a particular string boundary (chosen specifically so that this boundary string does not occur in any of the "value" payloads). Each part has its own set of MIME headers like <code>Content-Type</code>, and particularly <code>Content-Disposition</code>, which can give each part its "name." The value piece of each name/value pair is the payload of each part of the MIME message. The MIME spec gives us more options when representing the value payload -- we can choose a more efficient encoding of binary data to save bandwidth (e.g. base 64 or even raw binary).</p> <p>Why not use <code>multipart/form-data</code> all the time? For short alphanumeric values (like most web forms), the overhead of adding all of the MIME headers is going to significantly outweigh any savings from more efficient binary encoding.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload