1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
---
title: Accept
slug: Web/HTTP/Headers/Accept
translation_of: Web/HTTP/Headers/Accept
---
<div>{{HTTPSidebar}}</div>
<p><strong><code>Accept</code></strong> HTTP 請求標頭(以 <a href="/zh-TW/docs/Web/HTTP/Basics_of_HTTP/MIME_types">MIME type</a> 標示)會對伺服器告知用戶端可解讀的內容類型。伺服器可以透過 <a href="/zh-TW/docs/Web/HTTP/Content_negotiation">content negotiation</a> 來選用可行的協定,並以 {{HTTPHeader("Content-Type")}} 標頭告知用戶端。針對本標頭,瀏覽器可以根據完成請求的脈絡,來決定適合的數值:像是擷取 CSS 時,給予的值就會和圖片、影像、腳本不一樣。</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">標頭類型</th>
<td>{{Glossary("Request header")}}</td>
</tr>
<tr>
<th scope="row">{{Glossary("Forbidden header name")}}</th>
<td>no</td>
</tr>
<tr>
<th scope="row">{{Glossary("CORS-safelisted request header")}}</th>
<td>yes, with the additional restriction that values can't contain a <em>CORS-unsafe request header byte</em>: <code>"():<>?@[\]{}</code>, Delete, Tab and control characters: 0x00 to 0x19.</td>
</tr>
</tbody>
</table>
<h2 id="語法">語法</h2>
<pre class="syntaxbox">Accept: <MIME_type>/<MIME_subtype>
Accept: <MIME_type>/*
Accept: */*
// Multiple types, weighted with the {{glossary("quality values", "quality value")}} syntax:
Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8
</pre>
<h2 id="指令">指令</h2>
<dl>
<dt><code><MIME_type>/<MIME_subtype></code></dt>
<dd>一個精確的 <a href="/zh-TW/docs/Web/HTTP/Basics_of_HTTP/MIME_types">MIME type</a>,例如<code>text/html</code>。</dd>
<dt><code><MIME_type>/*</code></dt>
<dd>一個不指定子類的 MIME type。<code>image/*</code> 會配對到 <code>image/png</code>, <code>image/svg</code>, <code>image/gif</code> 和等圖片類型。</dd>
<dt><code>*/*</code></dt>
<dd>所有 MIME type</dd>
<dt><code>;q=</code> (q-factor weighting)</dt>
<dd>Any value used is placed in an order of preference expressed using relative <a href="/en-US/docs/Glossary/Quality_values">quality value</a> called the <em>weight</em>.</dd>
</dl>
<h2 id="示例">示例</h2>
<pre>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
</pre>
<h2 id="規範">規範</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">規範</th>
<th scope="col">標題</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{RFC("7231", "Accept", "5.3.2")}}</td>
<td>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context</td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
<p>{{Compat("http.headers.Accept")}}</p>
<h2 id="參見">參見</h2>
<ul>
<li>HTTP <a href="/zh-TW/docs/Web/HTTP/Content_negotiation">content negotiation</a></li>
<li>Header with the result of the content negotiation: {{HTTPHeader("Content-Type")}}</li>
<li>類似標頭:{{HTTPHeader("TE")}}, {{HTTPHeader("Accept-Encoding")}}, {{HTTPHeader("Accept-Charset")}}, {{HTTPHeader("Accept-Language")}}</li>
</ul>
|