错误:Axios API调用上的网络错误

时间:2018-02-07 10:10:38

标签: reactjs api request axios general-network-error

我正在使用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,则它可以正常工作。它也适用于具有root&#34; min-api.cryptocompare.com&#34;的任何其他CryptoCompare端点。

然而,所有的终端都遵循&#34; www.cryptocompare.com /&#34;模式不起作用。

我没有收到CORS错误。只是一个错误,表示&#34;错误:网络错误&#34;在Firefox中。

这是API本身的问题吗?或者我有什么东西可以忽略?

0 个答案:

没有答案