Accessing response headers on CORS request

回眸只為那壹抹淺笑 提交于 2019-12-11 04:39:46

问题


I'm using the fetch API to make a cross-domain request similar to the below snippet

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. I assume that's a CORS issue, because on local requests all headers are accessible.

Is that by design? Is there a way around that problem?


回答1:


The resource you are requesting most likely lacks a Access-Control-Expose-Headers header that contains Link as value.

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://stackoverflow.com/questions/32103768/accessing-response-headers-on-cors-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!