[英]Javascript fetch api : Can't retrieve some response header
我正在使用 javascript fetch API 使用以下代码查询跨域 api:
fetch('https://api.com/search?query="2016"').then(function (response) {
console.log(response.headers.get('Access-Control-Allow-Headers'))
console.log(response.headers.get('Content-Range'))
console.log(response.headers.get('Accept-Range'))
console.log(response.headers.get('Date'))
console.log(response.headers.get('Content-Type'))
})
响应头如下:
Accept-Range:cars 300
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Content-Range, Accept-Range
Access-Control-Allow-Methods:PUT, POST, OPTIONS, GET
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Connection:keep-alive
Content-Range:0-99/1941
Content-Type:application/json
Date:Tue, 12 Jan 2016 12:17:55 GMT
Transfer-Encoding:chunked
很奇怪的是,只有“内容类型”对其他人有效,我得到了null :
null
null
null
null
application/json
我需要做什么来检索这些空标头?
该死的,我使用的是“Access-Control-Allow-Headers”而不是“Access-Control-Expose-Headers”
它现在有效
使用CORS
包。 并把这个参数:
cors({credentials: true, origin: true, exposedHeaders: '*'})
就像在这里写的: https : //stackoverflow.com/a/64536201/2591785
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.