我正在尝试从meta weather api获取数据,但它没有让我 [英] I'm trying to get data from meta weather api, but its not letting me

查看:37
本文介绍了我正在尝试从meta weather api获取数据,但它没有让我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从meta weather API中获取数据.由于CORS问题,我正在使用这种名为"crossorigin.me"的代理服务器.仍然,它不让我获取数据.在许多人建议这样做之后,我什至包括了"mode:'no-cors".

I'm trying to get data from meta weather API. due to CORS issues, I am using this proxy thing called "crossorigin.me". still, its not letting me get the data. I even included "mode: 'no-cors" after many suggested to do so.

<!DOCTYPE html>
<html>
<head>
    <title> Fetch Promise </title>
</head>
<body>
<script>
    function getWeather(woeid){
    fetch(`https://crossorigin.me/https://www.metaweather.com/api/location/${woeid}/`,{mode: 'no-cors'})
//fetch always returns a promise
.then(data => {
    console.log(data)
    return data.json()
    // json also returns a promise so we handle that by chaining
})
.then(result => {
const today = result.consolidated_weather[0]
console.log(`temperature in ${result.title} stay between ${today.min_temp} and ${today.max_temp}`)
})
.catch(error => console.log(error)) 
}
getWeather(2487956)
</script>
</body>
</html

推荐答案

您使用的CORS解决方法服务可能由于交通繁忙或其他原因而无法使用.

It's possible the CORS workaround service you're using is unavailable, either due to a heavy traffic load or other reasons.

非常感谢,使用heroku设置自己的个人代理非常简单.

Thankfully, it's really, really easy to set up your own personal proxy using heroku.

按照此线程的第一个响应中的指示进行操作:

Follow the directions in the first response of this thread: cors-anywhere.herokuapp.com not working (503). What else can I try?

希望这会有所帮助.

这篇关于我正在尝试从meta weather api获取数据,但它没有让我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆