由于No' Access-Control-Allow-Origin'无法获得与Axios的链接请求.标头出现在请求的资源上 [英] Can't get request a link with Axios due to No 'Access-Control-Allow-Origin' header is present on the requested resource
问题描述
我正在尝试使用cryptocompare api来获取axios的coindata列表,但是我不知道该如何解决这个问题,我相信这是一个CORS问题,但是我不确定.
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.
完整错误如下:无法加载 https://www.cryptocompare.com/api/data/coinlist/:所请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许访问来源' http://localhost:3000 .响应的HTTP状态代码为524.
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.
我正在使用带有以下代码的axios:
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);
};
推荐答案
他们的API刚刚更改了您要获取的数据的网址.
Their API just changed the url for the data that you want to get.
https://min-api.cryptocompare.com/data/all/coinlist
我也已经使用axios对该URL进行了GET请求测试.
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);
});
希望对您有帮助.
这篇关于由于No' Access-Control-Allow-Origin'无法获得与Axios的链接请求.标头出现在请求的资源上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!