Brief analysis on the common form file upload of HTTP request header

Source: Internet
Author: User

First understand the difference between application/x-www-form-urlencoded and Multipart/form-data.

Application/x-www-form-urlencoded:

is a common form of forms, ordinary form submission, or JS package, by default, by this way,

<form enctype= "application/x-www-form-urlencoded" action="http// " method=" POST ">    <input type="text" name="name" value= "Homeway">    <input type="text" name= "key" value="Nokey" >    <input type="Submit" value="Submit"></Form 

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.


Multipart/form-data:

Upload a picture to see

Content-type:multipart/form-data; boundary=---------------------------27646987427698
content-length:198449

-----------------------------27646987427698
Content-disposition:form-data; Name= "x1"

52
-----------------------------27646987427698
Content-disposition:form-data; Name= "Y1"

The difference in personal understanding is that if there is no type=file control, the form form will automatically have the Enctype property of the form encoded by default application/x-www-form-urlencoded

, there are two kinds of commonly used: application/x-www-form-urlencoded and Multipart/form-data,

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).


There are two ways to submit data through a form, one is a get method, and the other is a POST
method, which is typically used to submit a small amount of data, and the Post method is applied when uploading a file or a large amount of data. In the HTML code, add the following code to the <form> tab to display a control that selects the file on the page.
<input type= "File" name= "FILE01" >
displayed on the page as follows (may vary depending on the browser) you can enter the file name directly in the text box, or you can click the button to pop up a dialog box for the user to select the file.
Browser encoding
When submitting a request to the server, the browser needs to submit a large amount of data to the server side, and before submission, the browser needs to be encoded in a way that is recognizable by the server side, which is simple for normal form data, and the encoded result is usually

The form of field1=value2&field2=value2&, such as the specific rules of this code can be found in the rfc2231, usually used in the form is also encoded in this way,

Servlet's
The API provides support for decoding this encoding, only calls to the ServletRequest
Class, you can get the fields and data in the user form.


This encoding method (

application/x-www-form-urlencoded

Although simple, it is not enough to transmit large chunks of binary data, for the transmission of such

Data, the browser uses a different encoding method, i.e.

"Multipart/form-data"



The encoding method, in this way, the browser can be very easy to form the data and

Files together. This encoding first defines the string that good one cannot appear in the data as a delimiter, and then uses it to separate the segments of the data, and for each data segment

Corresponds to an input area in an HTML page form, including a content-disposition

property, which describes some information about this data segment, if the data segment

The content is a file, there will be a Content-type attribute, and then the data itself.




Brief analysis on the common form file upload of HTTP request header

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.