首页 > 解决方案 > 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:无法获取

标签: javascript

解决方案


尝试将 url 放置在此代理之后:https://cors-anywhere.herokuapp.com/而不是https://crossorigin.me/

它对我有用。


推荐阅读