The difference and function of application/x-www-form-urlencoded multipart/form-data Text/plain

Source: Internet
Author: User

We know that it is best to specify the application/x-www-form-urlencoded encoding type by setting the request header when sending AJAX requests to the server via post. You must specify that the encoding type is "Multipart/form-data" when uploading a file through a form. And Text/plain is set when we are doing plain text transmission to prevent coding clutter when we receive data. But I haven't figured out why I'm setting this up. Later looked up some information to find the difference between the three.

application/x-www-form-urlencoded

This is the default encoding type when sending data through a form. We did not set the Enctype property in the from tag by default, which is the application/x-www-form-urlencoded type. The application/x-www-form-urlencoded encoding type encodes the data sent in the form into a name/value pair. This is the standard encoding format. When the action of the form is post, the browser encapsulates the form data into the HTTP body and sends it to the server. When the form's action is get, the application/x-www-form-urlencoded encoding type converts the data sent in the form into a string (name=coderbolg&key=php). Then append the string to the URL, split it, and then request the new URL. When we send AJAX requests to the server via post, it is best to specify the application/x-www-form-urlencoded encoding type by setting the request header. Method is added after the Xmlobject.open () method

Xmlobject . setRequestHeader ("Content-type","application/x-www-form-urlencoded")

Otherwise the server will not receive the post data.

Multipart/form-data

This is specifically used to transmit special types of data, such as the content of non-text we upload, than tablets or MP3. The Multipart/form-data encoding type encodes the data sent in the form into a single message, which is part of the message for each form control on the page. When the form has a file type control and wants it to work (nonsense) it must be set to the Multipart/form-data type, the browser splits the entire form in controls and adds content-disposition to each section ( Form-data or file), Content-type (default is Text/plain), name (control name) and so on, plus a separator (boundary).

Text/plain

The data is encoded in plain text, with no controls or formatting characters. There's nothing to say.

Related Article

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.