我正在开发webpack的开发服务器。当我尝试访问http://api.openweathermap.org/data/2.5/forecast?id=2848756&appid={api_key}时,我无法访问并且可以看到此日志。
XMLHttpRequest无法加载http://api.openweathermap.org/data/2.5/forecast?id={api_key}。航班前响应有无效的HTTP状态代码405
我试着设置webpack.config.js。就像低沉的场景。
devServer: {
contentBase: 'dist',
inline: true,
hot:true,
port: 8081,
proxy: {
'/**': {
target: 'http://api.openweathermap.org',
secure: false
}
}
但还是没用。你知道怎么解决吗?告诉我这件事。谢谢!
发布于 2017-04-16 09:29:56
尝试从您的headers
调用中删除axios.create()
属性,它们没有意义( Access-Control-*
属性是响应标头,而不是请求头,withCredentials
是选项,而不是头),并且可能会混淆浏览器,认为它需要执行一个看起来不像是OpenWeather API服务器应该执行的CORS预飞行:
const apiClient = API_URL => {
return axios.create({
baseURL : API_URL,
timeout : 100000,
withCredentials : 'true'
});
};
发布于 2017-04-16 08:14:05
您将不得不在开放的天气API网站上注册,然后您将获得API密钥,您将不得不使用该密钥来调用API。
在你打电话的时候
http://api.openweathermap.org/data/2.5/forecast?id=2848756&appid={api_key}
请在上述呼叫注册后插入api_key。假设注册后得到api_key as =xxxxxxx
在上面调用的http://api.openweathermap.org/data/2.5/forecast?id=2848756&appid=xxxxxxx中使用它
然后,您将收到JSON响应中的数据。欲了解更多信息,请访问
https://stackoverflow.com/questions/43435111
复制相似问题