在Http請求中,我們每天都在使用Content-type來指定不同格式的請求信息,但是卻很少有人去全面了解content-type中允許的值有多少,這里將講解Content-Type的可用值
MediaType,即是Internet Media Type
,互聯網媒體類型;也叫做MIME類型,在Http協議消息頭中,使用Content-Type來表示具體請求中的媒體類型信息。
例如: Content-Type: text/html;charset:utf-8;
常見的媒體格式類型如下:
text/html : HTML格式 text/plain :純文本格式 text/xml : XML格式 image/gif :gif圖片格式 image/jpeg :jpg圖片格式 image/png:png圖片格式
以application開頭的媒體格式類型:
application/xhtml+xml :XHTML格式 application/xml : XML數據格式 application/atom+xml :Atom XML聚合格式 application/json : JSON數據格式 application/pdf :pdf格式 application/msword : Word文檔格式 application/octet-stream : 二進制流數據(如常見的文件下載) application/x-www-form-urlencoded : <form encType=””>中默認的encType,form表單數據被編碼為key/value格式發送到服務器(表單默認的提交數據的格式)
另外一種常見的媒體格式是上傳文件之時使用的:
multipart/form-data : 需要在表單中進行文件上傳時,就需要使用該格式