Application/x-www-form-urlencoded and Multipart/form-data

Source: Internet
Author: User
Tags html form
Why do I have to add a property to the form where I uploaded the file enctypeUpload files in the form of <form> to add attributes Enctype= "Multipart/form-data", many people just rote know upload form to write, know it but do not know why. So why do you want to add this attribute anyway? What does it mean. What other optional value does it have? In fact, form forms when you do not write the enctype attribute, the default value is Enctype= "application/x-www-form-urlencoded." This property manages the MIME encoding of the form. There are three values to choose from:

①application/x-www-form-urlencoded (default value)

②multipart/form-data

③text/plain

Where ①application/x-www-form-urlencoded is the default value, you may have seen this in Ajax: Xmlhttp.setrequestheader ("Content-type", "application/ X-www-form-urlencoded "); The two things to do is to set the encoding of the form transfer. It is not possible to write an error in Ajax, but in HTML form table dropdowns can not write enctype= "application/x-www-form-urlencoded" because the default HTML form is this type of transmission encoding. And ②multipart-form-data is used to specify the special type of transmission data, mainly we upload the text of the content, such as pictures or MP3 and so on. ③text/plain is the meaning of pure text transmission, when sending mail to set this type of encoding, otherwise there will be the problem of coding confusion, the network often take text/plain and text/html do comparisons, in fact, these two very good distinction, the former used to transfer plain text files, The latter is the encoding type that passes the HTML code, which is only used when sending header files. ① and ③ can not be used to upload files, only multipart/form-data can complete the transfer of file data.

The mime mentioned above, its full name in English is the "Multipurpose Internet Mail Extensions" Multifunction Internet Mail Extension Service, a Multipurpose Internet Mail Extension Protocol, which was first applied to the e-mail system in 1992, But it was later applied to browsers. The server tells the browser the type of multimedia data they send, and the notification means the MIME type of the multimedia data to let the browser know which information is MP3 and which are Shockwave files and so on. The server puts the MIME markers in the transferred data to tell the browser which plug-in to use to read the related files.

In short, the MIME type is the type of file that sets an extension to open with an application, and when the file is accessed, the browser automatically opens with the specified application. Used to specify some client-defined file names and how some media files are opened.

After the browser receives the file, it goes to the plugin system to find out which plug-ins can recognize the files that are received by the read. If the browser does not know which plug-in system to call, it may tell the user that a plugin is missing, or that an existing plug-in may be selected directly to attempt to read the received file, which could cause the system to crash. The lack of a MIME identity in the transmitted information can be difficult to estimate because some computer systems may not fail, but some computers may crash as a result.

The steps to check whether a server correctly sets the MIME type are:

1. Open the Server Web page in Netscape browser

2. Go to the "View" menu and choose "Page Info"

3. Click "EMBED" in the upper frame in the pop-up window

4. See if the MIME type is "Application/x-director" or "Application/x-shockwave-flash" in the underlying frame, if the above information indicates that the server has set the MIME type correctly If the MIME type lists text content, eight-bit data, or other forms that indicate that the server's MIME type is not set correctly.

If the server does not correctly indicate the type of data it is sending, the server administrator should add the relevant information correctly, the method is very simple and quick.

Each MIME type is made up of two parts, preceded by a large category of data, such as sound audio, image image, and so on, followed by the definition of a specific kind.

Common MIME Types

Hypertext Markup Language text. html,.html text/html

Plain text. txt Text/plain

RTF text. rtf Application/rtf

GIF graphics. gif image/gif

JPEG Graphics-jpeg,.jpg image/jpeg

Au sound file. Au audio/basic

Midi Music file Mid,.midi Audio/midi,audio/x-midi

RealAudio music files. RA,. Ram Audio/x-pn-realaudio

MPEG files. Mpg,.mpeg video/mpeg

AVI file. avi Video/x-msvideo

gzip files. GZ application/x-gzip

Tar file. Tar Application/x-tar

There is a dedicated organization of the IANA on the Internet to confirm standard MIME types, but the Internet is growing too fast for many applications to wait for the IANA to confirm that the MIME types they use are standard types. So they use the method of X-opening in the category to identify that the category has not yet become a standard, such as X-gzip,x-tar. The fact that these types are widely used has become a fact standard. As long as both the client and the server recognize this MIME type, even if it is not a standard type, the client program can handle the data according to the MIME type using a specific processing method. For Web servers and browsers (including the operating system), the default is to set the standard and common MIME types, and only for unusual MIME types is it necessary to set up both the server and the client browser for identification.
----------------------------------------------------------------
The meaning of enctype= "Multipart/form-data" in the form is to set the MIME encoding of the form. By default,
This encoding format is application/x-www-form-urlencoded and cannot be used for file uploads;
Only the use of multipart/form-data, to complete the transfer of file data, to do the following operation.
Enctype= "Multipart/form-data" is the uploading of binary data; The value of the input in the form is passed in the form of 2.
The value of the input in the form is passed in the form of 2,
So the request is not worth it. In other words, add this code, use request will pass unsuccessful, take the form value to join the database, use the following:

Smartupload su = new smartupload ()//New Smartupload Object

Su.getrequest (). Getparametervalues (); take the array value

Su.getrequest (). GetParameter (); Take a single parameter single value

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.