我正在尝试使用开放式气象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);
})
但这给我一个错误
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
如果我使用邮递员发送发帖请求,该请求在那儿工作,请帮忙吗?
答案 0 :(得分:0)
其他有用的链接:cannot get cross-site POST to work,can not make post request ( cross domain ) 。基本上,这是浏览器安全问题,而不是Axios。他们不打算解决此问题:您选择另一个库或从后端处理它。请注意,在Chrome中禁用安全选项时,请求有效。