1

我正在使用 CryptoCompare API 为我的项目获取有关加密货币的数据。我已经向 API 发出了一些请求,并且没有问题得到响应。

API 的一些查询如下所示: https ://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=BTC,USD,EUR

其他的看起来像这样: https ://www.cryptocompare.com/api/data/coinsnapshot/?fsym=BTC&tsym=USD

当我向看起来像第一个的 URL 发出请求时,我能够从 API 获得响应并检索数据。当我提出相同的请求但对于看起来像第二个的 URL 之一时,我得到一个错误。错误:网络错误就是它所说的一切。

这是我的代码的样子:

import React, { Component } from 'react';
import axios from "axios";


class CoinInfo extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      coinInfo: []
    }
  }

  componentDidMount() {
    axios.get(`https://www.cryptocompare.com/api/data/coinsnapshot/?fsym=BTC&tsym=USD`)
    .then(res => {
      const info = res.data;
      this.setState({ coinInfo: info});
      console.log(info);
    });
  }



  render() {

    return (
      <div className="container">

      </div>
    )
  }
}

export default CoinInfo;

如果我换出 Axios 请求中的 URL 并将其替换为其他 API 端点/URL,它工作得很好。它也适用于任何其他具有根“min-api.cryptocompare.com”的 CryptoCompare 端点。

但是,所有遵循“www.cryptocompare.com/”模式的端点都不起作用。

我没有收到 CORS 错误。只是在 Firefox 中显示“错误:网络错误”的错误。

这是 API 本身的问题吗?还是我忽略了什么?

4

0 回答 0