1

我在 GitHub 页面上部署 React 应用程序时遇到了一个小问题。该应用程序在实时服务器上运行良好。但是,当我在 gitHub 上推送代码并对其进行测试时。发生此错误:

Mixed Content: the page at '<domain>' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoing 'http://www.omdbapi.com/...' ...

我知道这与我正在使用的 api 有关。它是omdb api,使用 HTTP 协议进行获取请求。我尝试将 HTTP 更改为 https,尽管它可以在实时服务器上运行。它不在 Github 页面上,给我和以前一样的错误。

代码:

const apirul = 'http://www.omdbapi.com/?apikey=...';
// ...
Axios(apiurl + "&=s="+state.s)
.then(data => {
  console.log(data);
  let results = data.Search;
  setState(prevState => {
    return { ...prevState, results }
  })
})
.catch(e => {
  console.log(e)
})
// ...
4

1 回答 1

2

查看GitHub Pages和它的源代码,我怀疑你推送到 GitHub 失败了,因为 repo 中的代码仍然指向http://www.omdbapi.com/?apikey=ad5bdfd0(并且最后一次更新是在 17 小时前)。我拍了一张截图来确认

将它的 URL 更改为https://应该可以修复它,但如果必须,您可以使用协议相对 url(即//)。 真的,你现在应该对所有事情都使用 https,甚至是本地开发。

于 2020-06-17T20:59:11.727 回答