Accept

Accept HTTP 請求標頭(以 MIME type 標示)會對伺服器告知用戶端可解讀的內容類型。伺服器可以透過 content negotiation 來選用可行的協定,並以 Content-Type 標頭告知用戶端。針對本標頭,瀏覽器可以根據完成請求的脈絡,來決定適合的數值:像是擷取 CSS 時,給予的值就會和圖片、影像、腳本不一樣。

標頭類型 Request header
Forbidden header name no
CORS-safelisted request header yes, with the additional restriction that values can't contain a CORS-unsafe request header byte: "():<>?@[\]{}, Delete, Tab and control characters: 0x00 to 0x19.

語法

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 type,例如text/html
<MIME_type>/*
一個不指定子類的 MIME type。image/* 會配對到 image/png, image/svg, image/gif 和等圖片類型。
*/*
所有 MIME type
;q= (q-factor weighting)
Any value used is placed in an order of preference expressed using relative quality value called the weight.

示例

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

規範

規範 標題
RFC 7231, section 5.3.2: Accept Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context

瀏覽器相容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
AcceptChrome Full support YesEdge Full support 12Firefox Full support Yes
Notes
Full support Yes
Notes
Notes In Firefox 66, the default Accept header value changed to */*.
IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support Yes
Notes
Full support Yes
Notes
Notes In Firefox 66, the default Accept header value changed to */*.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
See implementation notes.
See implementation notes.

參見