Can't get request a link with Axios due to No 'Access-Control-Allow-Origin' header is present on the requested resource

六月ゝ 毕业季﹏ 提交于 2019-12-11 02:13:44

问题


I am trying to use the cryptocompare api to get a list of coindata with axios but I can't figure out how to get around this issue I believe it's a CORS issue, but I am not sure.

The full error is as follows: Failed to load https://www.cryptocompare.com/api/data/coinlist/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 524.

I am using axios with the following code:

addCoinData(coinData) {
  axios.get('https://www.cryptocompare.com/api/data/coinlist/')
  .then(res => {
    const crypto = res.data;
    this.setState({crypto: crypto});
  })
  .catch(function (error) {
    console.log(error);
  });
  console.log(this.state.crypto);
};

回答1:


Their API just changed the url for the data that you want to get.

https://min-api.cryptocompare.com/data/all/coinlist

I've successfully made a GET request test with this url with axios as well.

axios.get('https://min-api.cryptocompare.com/data/all/coinlist')
  .then(res => {
    console.log(res.data)
})
  .catch(function (error) {
    console.log(error);
});

I hope it helps.



来源:https://stackoverflow.com/questions/46991663/cant-get-request-a-link-with-axios-due-to-no-access-control-allow-origin-head

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