aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/headers/append
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/headers/append')
-rw-r--r--files/zh-cn/web/api/headers/append/index.html84
1 files changed, 84 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/headers/append/index.html b/files/zh-cn/web/api/headers/append/index.html
new file mode 100644
index 0000000000..ca3477c5a0
--- /dev/null
+++ b/files/zh-cn/web/api/headers/append/index.html
@@ -0,0 +1,84 @@
+---
+title: Headers.append()
+slug: Web/API/Headers/append
+tags:
+ - Append
+ - Headers.append()
+translation_of: Web/API/Headers/append
+---
+<p>{{APIRef("Fetch")}}</p>
+
+<p>在一个<code>Headers</code>对象内部,{{domxref("Headers")}}接口的<strong><code>append()</code></strong>方法可以追加一个新值到已存在的headers上,或者新增一个原本不存在的header。</p>
+
+<p>{{domxref("Headers.set")}} 和 <code>append()</code> 两者之间的不同之处在于当指定header是已经存在的并且允许接收多个值时,{{domxref("Headers.set")}}会重写此值为新值,而<code>append()</code>会追加到值序列的尾部。</p>
+
+<p>因为安全性原因,一些headers仅受用户代理控制。包括{{Glossary("Forbidden_header_name", "forbidden header names", 1)}}和{{Glossary("Forbidden_response_header_name", "forbidden response header names", 1)}}。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="brush: js">myHeaders.append(name,value);</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><em>name</em></dt>
+ <dd>要追加给Headers对象的HTTP header名称.</dd>
+ <dt><em>value</em></dt>
+ <dd>要追加给Headers对象的HTTP header值.</dd>
+</dl>
+
+<h3 id="返回">返回</h3>
+
+<p>Void.</p>
+
+<h2 id="例程">例程</h2>
+
+<p>创建一个空的Headers对象:</p>
+
+<pre class="brush: js">var myHeaders = new Headers(); // Currently empty</pre>
+
+<p>可以通过append()方法添加header:</p>
+
+<pre class="brush: js">myHeaders.append('Content-Type', 'image/jpeg');
+myHeaders.get('Content-Type'); // Returns 'image/jpeg'
+</pre>
+
+<p>如果指定header不存在, <code>append()</code>将会添加这个header并赋值 . 如果指定header已存在并允许有多个值, <code>append()</code>将会把指定值添加到值队列的末尾。</p>
+
+<pre class="brush: js">myHeaders.append('Accept-Encoding', 'deflate');
+myHeaders.append('Accept-Encoding', 'gzip');
+myHeaders.getAll('Accept-Encoding'); // Returns [ "deflate", "gzip" ]
+</pre>
+
+<p>要使用新值覆盖旧值,请使用{{domxref("Headers.set")}}。</p>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Fetch','#dom-headers-append','append()')}}</td>
+ <td>{{Spec2('Fetch')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("api.Headers.append")}}</p>
+
+<div id="compat-mobile"> </div>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li>
+ <li><a href="/en-US/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li>
+ <li><a href="/en-US/docs/Web/HTTP">HTTP</a></li>
+</ul>