Weather API 请求 cors 错误 [英] Weather API request cors error
问题描述
我正在尝试从黑暗天空 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.net/forecast/febb2871126cd24613f32a79c32d4158/38.5815719,-121.4943996.请求的资源上不存在Access-Control-Allow-Origin"标头.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
这篇关于Weather API 请求 cors 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!