According to the http/1.1 RFC 2616 protocol, we only request options,, POST, PUT, DELETE, Trace, and so on, why do we still have the Multipart/form-data request? This is going to start from the beginning.
The HTTP protocol specifies an ASCII code transmission, which establishes the reference specification for IQ in the TCP,IP protocol, which divides the HTTP request into 3 parts, the status line, the request header, and the request body. All the methods, implementation are around how to use and organize the three parts to complete, original aim, HTTP knowledge we can ask degrees Niang.
Since there is no multipart/form-data in the above request method, then this request is how it is, in fact, is one thing, Multipart/form-data is also on the basis of post evolution, the following:
The basic way of 1.multipart/form-data is post, that is, it is implemented by the post combination method.
The difference between the 2.multipart/form-data and the Post method is the request header and the request body.
3.multipart/form-data's request header must contain a special header message: Content-type, whose value must also be multipart/form-data, and also require a content split to split the content of multiple posts in the request. If the file content and text content is to be separated, otherwise the receiver will not be able to parse and restore this file, the specific header information is as follows:
Content-type:multipart/form-data; Boundary=${bound}
Where ${bound} is a placeholder, on behalf of our specified separator, can be arbitrarily specified, but in order to avoid and normal text duplication, try to use a bit more complex content. Example:--------------------56423498738365
The 4.multipart/form-data request body is also a string, but unlike the post request, it is constructed in such a way that post is a simple Name=value key value connection, and multipart/ Form-data is a constructor that adds content such as delimiters, as follows:
--${bound}content-disposition:form-data; Name= "Filename"http.pdf--${bound}content-disposition:form-data; Name= "file000"; Filename= "HTTP protocol detailed. pdf"content-type:application/octet-stream%pdf-1.5file contentpercentEOF --${bound}content-disposition:form-data; Name= "Upload"Submit Query--${bound}--
Where ${bound} is the delimiter in the previous header information, if the header information is stated to be 123, then this is also 123; it is easy to see that this request is made up of multiple identical parts: Each part begins with a-plus delimiter, then a description of the content, then a carriage return, It then describes the specific content of the message, and if the content is a file, it also contains the file name information and the type of the document content. The second part of the above is the structure of a file body, and finally, the end of the delimiter--end, indicates that the request body.
Can know to send a multipart/form-data request, in fact any support POST request of the tool or language can support, just want to pack a little bit.
What is a multipart/form-data request