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

Request接口的只读属性  headers 包含与当前请求关联的Headers对象.

语法

var myHeaders = request.headers;

一个 Headers 对象.

例子

在下面的代码段中,我们使用 Request.Request() 构造函数(为获取与脚本处于同一目录的图片文件)创建新请求,然后将请求headers保存到变量中:

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

使用 Headers.appendHeaders 对象中添加header;然后,使用第二个init参数创建一个新的 Request ,同时,传递headers作为一个init选项:

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'

规范

Specification Status Comment
Fetch
headers
Living Standard Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Experimental
Chrome Full support 42
Full support 42
Full support 41
Disabled
Disabled From version 41: this feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Full support YesFirefox Full support 39
Full support 39
Full support 34
Disabled
Disabled From version 34: this feature is behind the dom.fetch.enabled preference. To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 29
Full support 29
Full support 28
Disabled
Disabled From version 28: this feature is behind the Experimental Web Platform Features preference.
Safari No support NoWebView Android No support NoChrome Android No support 42 — 46Edge Mobile Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android Full support 4.0

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also

文档标签和贡献者

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