Cors issue with third party api

2019-07-17 05:13发布

I am struggle with getting data from third party api on browser. 'https://www.coinexchange.io/api/v1/getmarkets'

I set mode:'no-cors' as option because it seems the response header does not include Access-Control-Allow-Origin. But mode: no-cors does not allow me to access to the data.

function callApi({ url }) {

  return fetch(url, {
    mode: 'no-cors'
  })
  .then(response => {
    if (!response) {
    }

    return response.json()
  })
  .then(response => {
    const camelizedJson = camelizeKeys(response)

    return Object.assign({},
      normalize(camelizedJson),
    )
  })

}

The response returns type: opaque like this image and response headers is this

I believe mode: no-cors works like sending GET request from HTML img tag so I can not use the information.

Is there any way to access to the third party API whose response header does not have Access-Control-Allow-Origin? How am I supposed to call third party public api?

If you have any ideas to fix this problem, please let me know! Thank you

0条回答
登录 后发表回答