Form content types(表單內容類型)--application/x-www-form-urlencoded和multipart/form-data


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






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章