天气API请求更正错误 [英] Weather API request cors error

查看:52
本文介绍了天气API请求更正错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从黑暗的天空api获取天气数据,并且不断收到cors错误.这是我的代码:

I am trying to get weather data from dark sky api and I keep getting a cors error. Here is my code:

var url = `https://api.darksky.net/forecast/febb2871126cd24613f32a79c32d4158/${lat},${lon}`;
axios.get(url, config).then(response => {
    this.setState({
        ...
    })
}).catch(function (error) {
    console.log(error);
});

我收到一个错误"XMLHttpRequest无法加载 https://api.darksky.net/forecast/febb2871126cd24613f32a79c32d4158/38.5815719,-121.4943996 .请求的资源上没有"Access-Control-Allow-Origin"标头.来源" https://ebcperez.github.io '因此不允许访问."

I get an error "XMLHttpRequest cannot load https://api.darksky.net/forecast/febb2871126cd24613f32a79c32d4158/38.5815719,-121.4943996. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://ebcperez.github.io' is therefore not allowed access."

推荐答案

我遇到了同样的问题,但是我解决了

I got a same issue But i solved that

像这样:" https://cors-Anywhere.herokuapp.com/http://samples.openweathermap.org/data/2.5/forecast?appid= {your_Api_key}"

like this : "https://cors-anywhere.herokuapp.com/http://samples.openweathermap.org/data/2.5/forecast?appid={your_Api_key}"

https://api.openweathermap.org/data/2.5/forecast?appid =

所以我不知道该URL不会发生错误

So i don't know that url will be didn't occur error

这篇关于天气API请求更正错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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