未捕获(承诺中)错误:React 应用程序 newsapi 调用中请求失败,状态代码为 426

问题描述 投票:0回答:1

我有一个托管在 Github 上的 React 应用程序,它可以调用 newsapi.org API。在本地,该应用程序工作正常,但在某些浏览器(即 chrome)的 gh-pages URL 中,我收到以下错误,该错误不允许加载 newsapi 信息:

Unchecked runtime.lastError: The message port closed before a response was received.
GET https://newsapi.org/v2/top-headlines?country=us&apiKey=7a4e481d736140efae783b1bfd607fbe 426
createError.js:16 
Uncaught (in promise) Error: Request failed with status code 426
    at e.exports (createError.js:16)
    at e.exports (settle.js:17)
    at XMLHttpRequest.p.onreadystatechange (xhr.js:61)

存储库位于 https://github.com/MarkMGill/Newscast,gh-pages URL 为 https://markmgill.github.io/Newscast/。我尝试用谷歌搜索 426,但找不到很多有用的信息。感谢任何可能知道如何解决此问题的人。

reactjs api github
1个回答
3
投票

刚刚研究了一些,发现新信息称 newsapi.org 已将其免费服务更改为仅允许本地 API 调用。这解释了为什么我的 gh-pages 中的应用程序不再加载 API 信息。

© www.soinside.com 2019 - 2024. All rights reserved.