Reactjs 无法获取API

Reactjs 无法获取API,reactjs,api,Reactjs,Api,我正在从OMDB API获取一个API,我得到了这个输出(TypeError:Failed to fetch) 我和邮递员一起测试了API,得到了积极的回应。我的应用程序只有一个输入框和一个搜索按钮!当用户输入标题时,它应该显示电影 class App extends React.Component { //state that stores the movies fetched from imdb database state = { movies: [] } //se

我正在从OMDB API获取一个API,我得到了这个输出
(TypeError:Failed to fetch)

我和邮递员一起测试了API,得到了积极的回应。我的应用程序只有一个输入框和一个搜索按钮!当用户输入标题时,它应该显示电影

class App extends React.Component {
  //state that stores the movies fetched from imdb database
  state = {
    movies: []
  }
  //sendRequest function that uses unirest to get our movie information. 
  sendRequest = (Title) => {
    const req = unirest("GET", "http://www.omdbapi.com/?i=tt3896198&apikey=275a2eec");
    req.query({
      "page": "1",
      "r": "json",
      "s": Title
    });
    req.headers({
      "x-rapidapi-host": "The OMDb API",
      "x-rapidapi-key": "275a2eec"
    });
    req.end((res) => {
      if (res.error) throw new Error(res.error);
      //We’re pulling our movies out of the response data, and storing them in our app state.
      const movies = res.body.Search;
      this.setState({
        movies
      });
      console.log(res.body);
    });
  }
}

检查响应标题中的
访问控制允许原点
。如果它们不匹配,那么react的fetch API会抛出那个错误。怎么办呢?我完全不懂做一个req