[英]Response for preflight does not have HTTP ok status in axios
i am trying to add stations using open weather api and doing post request using axios 我正在尝试使用开放式天气api添加站点并使用axios进行发布请求
const stationData={
external_id:this.state.external_id,
name:this.state.name,
latitude:this.state.latitude,
longitude:this.state.longitude,
altitude:this.state.altitude,
}
const url = `http://api.openweathermap.org/data/3.0/stations?appid=${ApiKey}`;
var headers = {
'Content-Type': 'application/json;charset=UTF-8',
"Access-Control-Allow-Origin": "*"
}
axios.post(url, data, {headers: headers}).then((response)=>{
console.log("response is " + response);
}).catch((err)=>{
console.log("error is " + err);
})
but it is giving me an error 但这给我一个错误
OPTIONS http://api.openweathermap.org/data/3.0/stations?APPID=2747592557924542516e283a7f905a81 404 (Not Found)
Failed to load http://api.openweathermap.org/data/3.0/stations?APPID=2747592557924542516e283a7f905a81: Response for preflight does not have HTTP ok status.
error is Error: Network Error
if i use the Postman to send the post request, its working there, any help please?? 如果我使用邮递员发送发帖请求,则该请求在那里工作,请提供任何帮助?
From Axios Git: Unfortunately, I think this boils down to one of the dreaded CORS issues that developers often face. 来自Axios Git: 不幸的是,我认为这可以归结为开发人员经常面临的可怕的CORS问题之一。 I could duplicate this and I tried a bunch of ways to poke at it to get the preflight request to work, but I couldn't find an opening in the server to let me through 我可以重复此操作,并尝试了多种方法来戳它,以使印前检查请求正常工作,但是我找不到服务器上的开口让我通过
Other useful links: cannot get cross-site POST to work , can not make post request ( cross domain ) . 其他有用的链接: 无法获得跨站点POST的工作 , 无法发出发布请求(跨域) 。 Basically it is a browser security issue rather than Axios. 基本上,这是浏览器安全问题,而不是Axios。 They are not planning to address that: either you choose another library or handle it from your backend. 他们不打算解决此问题:您选择另一个库或从后端处理它。 Note that with security disabled option in Chrome the request works. 请注意,在Chrome中禁用安全选项时,请求有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.