Http Protocol data transmission in a multiple form submission--multipart/form-data

来源:互联网 发布:战舰世界舰船数据 编辑:程序博客网 时间:2024/06/06 08:48

http://www.cnblogs.com/shanyou/archive/2013/06/07/3123155.html

RFC 2188:Returning Values from Forms:multipart/form-data, this document explains the practice of using HTTP POST message information in multiple formats, it can be used in many REST-based API system, it can mix a variety of data formats and transmission at a time, of course, non-text data must be encoded as a binary string.

RFC 2387 files, pointed out that to transport multiple parameters, multiple information types mixed information, first set the HTTP request Content-Type to multipart/form-data, and to set a boundary parameter, this parameter is generated by the application itself, it is used to identify every boundaries of information (boundary) for manifold information (message part), andHTTP POST HTTP server can crawl information and adopt a familiar object model exposed to server reads (ex:ASP.NET Request.Form).

Below is a multipart/form-data of multiple parameters of messages (source:RFC 2388):

Content-Type: multipart/form-data; boundary=MYBOUNDARY

--MYBOUNDARY

Content-Disposition: form-data; name="[PARAMETER-NAME]"

<NEWLINE>

<NEWLINE>

<Data goes here>

--MYBOUNDARY

Content-Disposition: form-data; name="[PARAMETER-NAME]"

<NEWLINE>

<NEWLINE>

<Data goes here>

--MYBOUNDARY

Content-Disposition: form-data; name="[PARAMETER-NAME]"

Content-Type: image/jpeg

<NEWLINE>

<NEWLINE>

<Image data goes here>

--MYBOUNDARY

Above seem pretty hard to understand, but the basic concepts are:

1. each information--[BOUNDARY_NAME] wrap to separate each part of the information, and finally add another--[BOUNDARY_NAME] to indicate the end.

2. each part have a Content-Disposition:form-data of information;Name = "", and the key value name is set by HTTP POST (key).

3. declarations and values across two new line symbols (. NET, Environment.NewLine is).

4. can clip into binary data, but binary data must be formatted as a binary string, this work will be used by HttpWebRequest NetworkStream.Write () write upload information is automatically removed by the system.

5. to set a different piece of information data type (Content-Type), the declared area set in the information.

 

0 0
原创粉丝点击