![](/img/trans.png)
[英]Made sure content-type and content-encoding, still get 415 Unsupported media type
[英]What is the difference between Content-Type…charset=X and Content-Encoding=X?
是否有任何有效的區別
Content-Encoding: UTF-8
Content-Type: text/html; charset=utf-8
?
可選參數charset
僅適用於基於文本的內容( Content-Types
如text/plain
, text/html
等)。 並非所有消息都是文本。
Content-Encoding
意味着整個身體已經以某種方式編碼(通常是壓縮的)。 此標頭的典型值為gzip
和deflate
。 此消息的接收者應解碼(例如,ungzip)正文以獲取原始消息。
我甚至不確定UTF-8
是否有意義作為Content-Encoding
的值。
根據RFC 7231-超文本傳輸協議(HTTP / 1.1):語義和內容 , Content-Encoding
頭包含內容編碼值的列表。 引用RFC :
內容編碼值指示已經或可以應用於表示的編碼變換。 內容編碼主要用於允許表示被壓縮或以其他方式有用地轉換而不會丟失其底層媒體類型的身份並且不丟失信息。 通常,表示以編碼形式存儲,直接傳輸,並且僅由最終接收者解碼。
content-coding = token
所有內容編碼值都不區分大小寫,應該在“HTTP內容編碼注冊表”中注冊,如第8.4節中所定義。 它們用於Accept-Encoding(第5.3.4節)和Content-Encoding(第3.1.2.2節)頭字段。
第8.4節說:
“HTTP內容編碼注冊表”定義內容編碼名稱的名稱空間([RFC7230]的第4.2節)。 內容編碼注冊表保存在http://www.iana.org/assignments/http-parameters 。
注冊表目前列出:
br Brotli Compressed Data Format [RFC7932]
compress UNIX "compress" data format [RFC7230] Section 4.2.1
deflate "deflate" compressed data ([RFC1951]) [RFC7230] Section 4.2.2
inside the "zlib" data format ([RFC1950])
exi W3C Efficient XML Interchange
gzip GZIP file format [RFC1952] [RFC7230] Section 4.2.3
identity Reserved (synonym for "no encoding" in [RFC7231] Section 5.3.4
Accept-Encoding)
pack200-gzip Network Transfer Format for Java Archives
x-compress Deprecated (alias for compress) [RFC7230] Section 4.2.1
x-gzip Deprecated (alias for gzip) [RFC7230] Section 4.2.3
UTF-8是一種字符編碼方案 ,不能用於無損地轉換任意二進制數據(至少不會以任何有意義的方式)。 將Content-Encoding
設置為UTF-8
是完全錯誤的。 用戶代理可能只是忽略未知值或丟棄該消息並報告錯誤。 設置字符編碼方案的正確位置是Content-Type
標頭 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.