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

The headers read-only property of the Request interface contains the Headers object associated with the request.

语法

var myHeaders = request.headers;

Value

A Headers object.

例子

In the following snippet, we create a new request using the Request.Request() constructor (for an image file in the same directory as the script), then save the request headers in a variable:

var myRequest = new Request('flowers.jpg');
var myHeaders = myRequest.headers; // Headers {}

To add a header to the Headers object we use Headers.append; we then create a new Request along with a 2nd init parameter, passing headers in as an init option:

var myHeaders = new Headers();
myHeaders.append('Content-Type', 'image/jpeg');

var myInit = { method: 'GET',
                   headers: myHeaders,
                   mode: 'cors',
                   cache: 'default' };

var myRequest = new Request('flowers.jpg',myInit);

myContentType = myRequest.headers.get('Content-Type'); // returns 'image/jpeg'

Specifications

Specification Status Comment
Fetch
headers
Living Standard Initial definition

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

42

411

Yes

39

342

No

29

283

No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support No42 — 46 Yes No No No4.0

1. From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.

2. From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.

3. From version 28: this feature is behind the Experimental Web Platform Features preference.

See also

文档标签和贡献者

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