简体   繁体   English

在CORS请求上访问响应头

[英]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.

相关问题 在AJAX CORS请求中访问响应 - Accessing response in an AJAX CORS request 无法使用jQuery读取CORS请求的响应头 - Cannot read response headers for CORS request with jQuery 获取 API CORS 错误:预检响应中的 Access-Control-Allow-Headers 不允许请求 header 字段授权 - Fetch API CORS error: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response CORS 错误:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段授权 - CORS error :Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response 尽管配置了正确的 CORS 标头,但“跨源请求已阻止”的 301 响应 - 301 response with 'Cross-Origin Request Blocked' despite having correct CORS headers configured 被 CORS 阻止:在预检响应中 Access-Control-Allow-Headers 不允许请求 header 字段授权 - Being blocked by CORS: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response 用于访问另一个域上文件的CORS标头 - CORS headers for accessing a file on another domain 在responseError方法中访问响应头 - Accessing response headers in responseError method IE在回应中看不到CORS标头 - IE doesn't see CORS headers in response 启用CORS-自定义响应标头不匹配 - enabling CORS - custom response headers do not match
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM