Accept
Accept 請求 HTTP 頭部指示客戶端能夠理解的哪些內容型別,以 MIME 型別 表示。伺服器使用 內容協商 來選擇其中一個提案,並使用 Content-Type 響應頭通知客戶端其選擇。瀏覽器根據請求的上下文設定此標頭的所需值。例如,瀏覽器在獲取 CSS 樣式表、影像、影片或指令碼時,在請求中使用不同的值。
| 頭部型別 | 請求頭部 |
|---|---|
| 禁止的頭部名稱 | 否 |
| CORS 安全列表請求頭部 | 是,但附加限制是值不能包含CORS 不安全請求頭部位元組:0x00-0x1F(除了 0x09(HT)),"():<>?@[\]{} 和 0x7F(DEL)。 |
語法
http
Accept: <MIME_type>/<MIME_subtype>
Accept: <MIME_type>/*
Accept: */*
// Multiple types, weighted with the quality value syntax:
Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8
指令
<MIME_type>/<MIME_subtype>-
單個、精確的 MIME 型別,例如
text/html。 <MIME_type>/*-
MIME 型別,但沒有子型別。
image/*對應於image/png、image/svg、image/gif和其他影像型別。 */*-
任何 MIME 型別
;q=(q 因子權重)-
使用的值按優先順序排列,使用稱為權重的相對 質量值 表示。
示例
http
Accept: text/html
Accept: image/*
// General default
Accept: */*
// Default for navigation requests
Accept: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
規範
| 規範 |
|---|
| HTTP 語義 # field.accept |
瀏覽器相容性
BCD 表格僅在瀏覽器中載入
另請參閱
- HTTP 內容協商
- 預設 Accept 值列表
- 包含內容協商結果的頭部:
Content-Type - 其他類似的頭部:
TE、Accept-Encoding、Accept-Language