MDN wants to talk to developers like you: https://qsurvey.mozilla.com/s3/8d22564490d8

Headers.getAll()

这篇翻译不完整。请帮忙从英语翻译这篇文章

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

getAll() 方法会以数组形式返回指定header的所有值. 如果指定的header未存在,则返回一个空数组.

Note:出于安全原因, 部分头信息只能被用户代理控制. 这些头信息包括 forbidden header names  和 forbidden response header names.

Syntax

myHeaders.getAll(name);

Parameters

name
需检索的HTTP header名称. 如果HTTP header中不存在指定名称则抛出一个 TypeError.

Returns

An Array containing a ByteString sequence representing the values of the retrieved header.

Example

Creating an empty Headers object is simple:

var myHeaders = new Headers(); // Currently empty

You could add a header to this using Headers.append, then retrieve it using getAll():

myHeaders.append('Content-Type', 'image/jpeg');
myHeaders.getAll('Content-Type'); // Returns [ "image/jpeg" ]

If the header has multiple values associated with it, the array will contain all the values, in the order they were added to the Headers object:

myHeaders.append('Accept-Encoding', 'deflate');
myHeaders.append('Accept-Encoding', 'gzip');
myHeaders.getAll('Accept-Encoding'); // Returns [ "deflate", "gzip" ]

Note: Use Headers.get to return only the first value added to the Headers object.

Specifications

Specification Status Comment
Fetch
getAll()
Living Standard  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 42
41 behind pref
 
39 (39)
34 behind pref
未实现

29
28 behind pref

未实现
Feature Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support 未实现 未实现 未实现 未实现 未实现 未实现 未实现

See also

文档标签和贡献者

 此页面的贡献者: Taoja
 最后编辑者: Taoja,