9

このコードを使用してクロスドメイン API をクエリするために、javascript fetch 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

非常に奇妙なのは、「Content-Type」のみが他の人に対して機能していて、nullを取得していることです。

null
null
null
null
application/json

これらのnullヘッダーを取得するにはどうすればよいですか?

4

2 に答える 2

19

くそー、「Access-Control-Expose-Headers」の代わりに「Access-Control-Allow-Headers」を使用していました

それは今動作します

于 2016-01-12T14:29:52.253 に答える