javascript - net::ERR_CONNECTION_RESET, Uncaught (in promise) TypeError: Failed to fetch
问题描述
我是 JavaScript 新手,这是我第一次使用 API。所以我试图获取 MetaWeather API,我就是这样做的
fetch('https://crossorigin.me/https://www.metaweather.com/api/location/2487956/');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Asynchronous JavaScript</title>
</head>
<body>
<h1>Asynchronous JavaScript</h1>
</body>
</html>
我得到这两个错误,我真的不明白为什么。
asynchronous.html:101 GET https://crossorigin.me/https://www.metaweather.com/api/location/2487956/net::ERR_CONNECTION_RESET(匿名)@asynchronous.html:101 asynchronous.html:1 未捕获(在承诺中)TypeError:无法获取
解决方案
尝试将 url 放置在此代理之后:https://cors-anywhere.herokuapp.com/而不是https://crossorigin.me/
它对我有用。
推荐阅读
- python - 我不知道为什么python会抛出这个错误
- data-structures - 如何将日期列表过滤为长生不老药中的月份列表?
- sql - 一条一条插入记录
- python - 为什么这个简单的滚模代码不能“打印”任何东西?
- ruby-on-rails - Minitest + Capybara:如何检查选项列表是否不包含选项?
- r - 按最接近的日期连接两个数据框而不在 R 中遍历
- anaconda - 当安装的包使用 conda 虚拟环境时,如何使 Python 控制台脚本入口点工作?
- python - 如何解决此错误?AttributeError:“builtin_function_or_method”对象没有属性“数据”
- c# - C# 中的非阻塞 OpenGL (OpenTK) 游戏循环
- java - java.lang.NumberFormatException:对于输入字符串 {Date}。Spring MVC 我无法识别错误