因此,我部署了所有使用 API 的 React 应用程序。我在发送此 api 时遇到问题,并且某些东西阻止了它们,因此我的应用程序无法运行。
注意:我的所有请求都是cors,所以没有问题。
这是图片中项目的链接 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/