application/x-www-form-urlencoded vs. multipart/form-data
application/x-www-form-urlencoded vs. multipart/form-data
關於application/x-www-form-urlencoded等字符編碼的解釋說明 在Form元素的語法中,EncType表明提交數據的格式用Enctype屬性指定將數據回發到服務器時瀏覽器使用的編碼類型。下邊是說明: application/x-www-form-urlencoded:窗體數據被編碼為名稱/值對。這是標準的編碼格式。multipart/form-data:窗體數據被編碼為一條消息,頁上的每個控件對應消息中的一個部分。text/plain:窗體數據以純文本形式進行編碼,其中不含任何控件或格式字符。 補充 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)。http://en.wikipedia.org/wiki/POST_(HTTP)
When a web browser sends a POST request from a web form element, the default Internet media type is "application/x-www-form-urlencoded".[8] This is a format for encoding key-value pairs with possibly duplicate keys. Each key-value pair is separated by an '&' character, and each key is separated from its value by an '=' character. Keys and values are both escaped by replacing spaces with the '+' character and then using URL encoding on all other non-alphanumeric[9] characters. For example, the key-value pairs
Name: Jonathan Doe Age: 23 Formula: a + b == 13%!are encoded as
Name=Jonathan+Doe&Age=23&Formula=a+%2B+b+%3D%3D+13%25%21Starting with HTML 4.0, forms can also submit data in multipart/form-data as defined in RFC 2388 (See also RFC 1867 for an earlier experimental version defined as an extension to HTML 2.0 and mentioned in HTML 3.2). http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
沒有留言:
張貼留言