The difference between application/x-www-form-urlencoded and Multipart/form-data

Source: Internet
Author: User

When learning <form> elements, the enctype attribute has three values

Enctype attribute table:

value /th>
application/x-www-form-urlencoded Encode all characters before sending (default)
multipart/form-data

text/plain spaces are converted to "+" plus signs, but no special characters are encoded.

Where the,<input> element's type attribute must be file when the value is Multipart/form-data.

Type attribute table:

value Description
button Define clickable buttons (in most cases, use JavaScript to launch scripts).
CheckBox Define the check box.
File Define input fields and "Browse" buttons for file uploads.
Hidden Defines the hidden input field.
Image Defines the submit button in the form of an image.
Password Defines the password field. The characters in the field are masked.
Radio Defines a radio button.
Reset Defines the reset button. The reset button clears all the data from the form.
Submit Define the Submit button. The Submit button sends the form data to the server.
Text Defines an input field for a single line in which the user can enter text. The default width is 20 characters.

Later, when I was learning the requests module, I came into contact with application/x-www-form-urlencoded and Multipart/form-data, and said the following:

The enctype represents the MIME encoding.

application/x-www-form-urlencoded: The form data is encoded as a name/value pair. This is the standard encoding format.

Multipart/form-data: The form data is encoded as a message, and each control on the page corresponds to a part of the message.

Text/plain: Form data is encoded in plain text with no control or formatting characters.

Add

The Enctype property of a form is encoded in two common ways: application/x-www-form-urlencoded and Multipart/form-data, which are application/by default. X-www-form-urlencoded.

When action is get, the browser uses x-www-form-urlencoded encoding to convert the form data into a string (Name1=value1&name2=value2 ... ), and then append the string to the URL, using the. Split, to load the new URL.

When the action is post, the browser encapsulates the form data into the HTTP body and then sends it to the server.

If you don't have a type=file control, you can use the default application/x-www-form-urlencoded.

But if you have type=file, you will need to use Multipart/form-data. The browser splits the entire form into units of control and adds content-disposition (form-data or file), Content-type (default = Text/plain), name (control name), and so on for each section. and add the separator (boundary).

Summarize

The message body is tagged, which is the MIME type. With this tag, the browser and server will be able to know the type of the data and then use the appropriate way to process the data.

MIME type structure

The difference between application/x-www-form-urlencoded and Multipart/form-data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.