javascript - 来自 GitHub 页面的 API 请求不起作用 ("mixed block")

标签 javascript reactjs api github github-pages

因此,我部署了所有使用 API 的 React 应用程序。我在发送此 api 时遇到问题,并且某些东西阻止了它们,因此我的应用程序无法运行。

注意:我的所有请求都是cors,所以没有问题。

github block my request

这是图片中项目的链接 news-blog

最佳答案

问题在于您尝试从安全 (https) 站点获取非安全 (http) 内容,这违反了该站点的 Content-Security-Policy (CSP) 。就现代浏览器而言,这是一种不安全的行为。

来自 MDN:

The HTTP Content-Security-Policy response header allows web site administrators to control resources the user agent is allowed to load for a given page. With a few exceptions, policies mostly involve specifying server origins and script endpoints. This helps guard against cross-site scripting attacks (XSS).

解决此问题的正确方法是从安全源加载数据。例如,不要从 http://newsapi.org/v2/everything 获取,而是尝试 https://newsapi.org/v2/everything (请注意之间的区别http 和 https)。

关于javascript - 来自 GitHub 页面的 API 请求不起作用 ("mixed block"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60698563/

相关文章:

javascript - 对 Backbone 进行子类化。查看子类并保留事件

c# - 如何将公共(public) Web 服务 API 设为私有(private)?

php - PHP的Youtube API引用代码?

javascript - 在 JS 中将小时和分钟显示为单词

javascript - 在 JavaScript 中调用 DatePicker 的最佳方式是什么

javascript - React ANTD DatePicker HTMLCollection 在提取元素/值时不显示实时值

reactjs - React-Redux - Hooks API

reactjs - 如何让父组件仅在单击按钮时将 prop 传递给子组件

javascript - 如何获取循环中给定值的总和?

JavaScript 减少 Promise 不按顺序返回