Http Header里的Content-Type一般有這三種:
application/x-www-form-urlencoded:數(shù)據(jù)被編碼為名稱/值對(duì)。這是標(biāo)準(zhǔn)的編碼格式。
multipart/form-data: 數(shù)據(jù)被編碼為一條消息,頁上的每個(gè)控件對(duì)應(yīng)消息中的一個(gè)部分。
text/plain: 數(shù)據(jù)以純文本形式(text/json/xml/html)進(jìn)行編碼,其中不含任何控件或格式字符。postman軟件里標(biāo)的是RAW。(使用text/plain方式:一般向服務(wù)端發(fā)送json數(shù)據(jù)會(huì)使用這種方式。)
form的enctype屬性為編碼方式,常用有兩種:application/x-www-form-urlencoded和multipart/form-data,默認(rèn)為application/x-www-form-urlencoded。
當(dāng)action為get時(shí)候,瀏覽器用x-www-form-urlencoded的編碼方式把form數(shù)據(jù)轉(zhuǎn)換成一個(gè)字串(name1=value1&name2=value2...),然后把這個(gè)字串追加到url后面,用?分割,加載這個(gè)新的url。
當(dāng)action為post時(shí)候,瀏覽器把form數(shù)據(jù)封裝到http body中,然后發(fā)送到server。 如果沒有type=file的控件,用默認(rèn)的application/x-www-form-urlencoded就可以了。 但是如果有type=file的話,就要用到multipart/form-data了。
當(dāng)action為post且Content-Type類型是multipart/form-data,瀏覽器會(huì)把整個(gè)表單以控件為單位分割,并為每個(gè)部分加上Content-Disposition(form-data或者file),Content-Type(默認(rèn)為text/plain),name(控件name)等信息,并加上分割符(boundary)。
學(xué)習(xí)使用,轉(zhuǎn)自:https://www.cnblogs.com/52fhy/p/5436673.html