[英]Accessing response headers on CORS request
I'm using the fetch API to make a cross-domain request similar to the below snippet 我正在使用访存API发出与以下代码段类似的跨域请求
window.fetch('http://data.test.wikibus.org/magazines', { method: 'get'}) .then(function(response) { var linkHeader = response.headers.get('Link'); document.querySelector('#link-header').innerText = 'The Link header is: ' + linkHeader; });
<span id="link-header"></span>
As you see the Link header (and some other headers too) is not accessible although it is returned in the response. 如您所见,尽管Link标头(以及其他一些标头)在响应中返回,但仍不可访问。 I assume that's a CORS issue, because on local requests all headers are accessible.
我认为这是一个CORS问题,因为在本地请求上所有标头都是可访问的。
Is that by design? 这是设计使然吗? Is there a way around that problem?
有办法解决这个问题吗?
The resource you are requesting most likely lacks a Access-Control-Expose-Headers
header that contains Link
as value. 您所请求的资源很可能缺少包含
Link
作为值的Access-Control-Expose-Headers
标头。
See https://fetch.spec.whatwg.org/#http-access-control-expose-headers and see https://fetch.spec.whatwg.org/#concept-filtered-response-cors for the details of which headers get filtered out of a CORS response. 请参阅https://fetch.spec.whatwg.org/#http-access-control-expose-headers,并参阅https://fetch.spec.whatwg.org/#concept-filtered-response-cors了解详细信息标头会从CORS响应中过滤掉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.