首页 > 解决方案 > API 请求被阻止,内容必须通过 HTTPS 提供

问题描述

我使用 api 调用创建了一个角度应用程序。我已经将它部署在 github 页面中。然后,当每次 api 调用时,我都会收到此错误消息。

getList(input) {

  const url = '/api.themoviedb.org/3/search/movie/?api_key=b6dba21fefcead3510c8ddf58eb57d43&query=' + input;
  return this.httpClient.get<RootResult>(url);
}

我在开发工具控制台中收到此错误:

Mixed Content: The page at 'https://githamza.github.io/ngxs-app-example/home' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.themoviedb.org/3/search/movie?api_key=b6dba21fefcead3510c8ddf58eb57d43&query=l'. This request has been blocked; the content must be served over HTTPS.

我在我的 api 中使用相对路径,但它总是添加http而不是https

这是我的 github 页面示例:https ://githamza.github.io/ngxs-app-example

标签: javascriptangularapitypescripthttps

解决方案


您的 API 在 http 后面,因此您不能从 https(客户端)应用程序调用 http api,这违反了 https 安全策略.. 应用程序和 api 都应该使用相同的协议

更新:将网址更改为如下

const url = 'https://api.themoviedb.org/3/search/movie/?api_key=b6dba21fefcead3510c8ddf58eb57d43&query=' + input;

推荐阅读