您的位置:首页 > 移动开发

Form content types(表单内容类型)--application/x-www-form-urlencoded和multipart/form-data

2017-03-02 00:13 513 查看
RFC
点击打开链接

通读全文,更好的理解get/post请求和传递数据。

--------multipart/form-data 

The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters.

表单内容类型"application/x-www-form-urlencoded"不能用来发送大量的二进制数据或者包含非ASCII字符的文本。

The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.

而表单内容类型"multipart/form-data"用来提交文件、非ASCII字符数据和二进制数据。

被设计用来提交文件、非ASCII字符数据 和 大量二进制数据。

常见用法,Http的post方式提交数据。

--------application/x-www-form-urlencoded 

This is the default content type. Forms submitted with this content type must be encoded as follows:

默认类型。表单在提交前要按照下面的方式编码。

Control names and values are escaped(转义). Space characters are replaced by `+', and then reserved characters are escaped as described in [RFC1738],

section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character.

 Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').

The control names/values are listed in the order they appear in the document.

The name is separated from the value by `=' and name/value pairs are separated from each other by `&'.

理解就是URLEncode,常见用法Http的get请求url编码;

==========其他人的理解==========

是Form的2种编码方式(encType) 
点击打开链接

======MediaType介绍=======点击打开链接

======Http支持的ContentType===点击打开链接

==========================


form的enctype属性为编码方式,常用有两种:application/x-www-form-urlencoded和multipart/form-data,默认为application/x-www-form-urlencoded。 当action为get时候,浏览器用x-www-form-urlencoded的编码方式把form数据转换成一个字串(name1=value1&name2=value2...),然后把这个字串append到url后面,用?分割,加载这个新的url。
当action为post时候,浏览器把form数据封装到http body中,然后发送到server。 如果没有type=file的控件,用默认的application/x-www-form-urlencoded就可以了。 但是如果有type=file的话,就要用到multipart/form-data了。浏览器会把整个表单以控件为单位分割,并为每个部分加上Content-Disposition(form-data或者file),Content-Type(默认为text/plain),name(控件name)等信息,并加上分割符(boundary)。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  FormType
相关文章推荐