【问题标题】:Getting mixed content error while making this request (even though it is https)发出此请求时出现混合内容错误(即使它是 https)
【发布时间】:2021-05-08 23:43:18
【问题描述】:

我正在通过使用 reactjs 构建一个小型电影搜索应用来练习 fetch-api。

它在 localhost 上运行良好,但是当我在 netlify 上部署它时出现此错误。

混合内容:“https://movie-search-abhi28069.herokuapp.com/”的页面是通过 HTTPS 加载的,但请求了不安全的资源“http://api.themoviedb.org/3/search/”电影?api_key=####&query=prime'。此请求已被阻止;内容必须通过 HTTPS 提供。

fetch(
        "https://api.themoviedb.org/3/search/movie/?api_key=####&query=" +
          term
      )
        .then((res) => res.json())
        .then((data) => setMovies(data.results))
        .catch((err) => console.log(err));

当组件被加载以获取热门电影时,我还有另一个 fetch 调用,它工作正常。不知道为什么我的搜索请求会自动转换为 http

【问题讨论】:

    标签: reactjs fetch-api mixed-content themoviedb-api


    【解决方案1】:

    根据https://www.themoviedb.org/talk/5dd34e7957d3780015dcfd99
    使用尾部斜杠,您的请求将被重定向到 http。
    删除尾部斜杠将解决问题。

    fetch(
        "https://api.themoviedb.org/3/search/movie?api_key=####&query=" +
          term
      )
        .then((res) => res.json())
        .then((data) => setMovies(data.results))
        .catch((err) => console.log(err));
    

    【讨论】:

      猜你喜欢
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 2018-04-02
      • 2021-05-10
      • 2020-02-01
      • 1970-01-01
      • 2016-03-01
      • 2015-08-12
      相关资源
      最近更新 更多