由于请求的资源上不存在 'Access-Control-Allow-Origin' header,因此无法通过 Axios 获取请求 link
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 的硬币数据列表,但我不知道如何解决这个问题我认为这是一个 CORS 问题,但我不确定.
完整错误如下:
无法加载 https://www.cryptocompare.com/api/data/coinlist/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' 因此不允许访问。响应具有 HTTP 状态代码 524。
我正在使用带有以下代码的 axios:
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 刚刚更改了您想要获取的数据的 url。
https://min-api.cryptocompare.com/data/all/coinlist
我已经成功地用这个 url 和 axios 进行了 GET 请求测试。
axios.get('https://min-api.cryptocompare.com/data/all/coinlist')
.then(res => {
console.log(res.data)
})
.catch(function (error) {
console.log(error);
});
希望对您有所帮助。
我正在尝试使用 cryptocompare api 来获取带有 axios 的硬币数据列表,但我不知道如何解决这个问题我认为这是一个 CORS 问题,但我不确定.
完整错误如下: 无法加载 https://www.cryptocompare.com/api/data/coinlist/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' 因此不允许访问。响应具有 HTTP 状态代码 524。
我正在使用带有以下代码的 axios:
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 刚刚更改了您想要获取的数据的 url。
https://min-api.cryptocompare.com/data/all/coinlist
我已经成功地用这个 url 和 axios 进行了 GET 请求测试。
axios.get('https://min-api.cryptocompare.com/data/all/coinlist')
.then(res => {
console.log(res.data)
})
.catch(function (error) {
console.log(error);
});
希望对您有所帮助。