gpt4 book ai didi

javascript - 预检响应在 axios 中没有 HTTP ok 状态

转载 作者:行者123 更新时间:2023-11-30 06:22:27 25 4
gpt4 key购买 nike

我正在尝试使用 open weather 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

如果我使用 postman 发送邮寄请求,它在那里工作,请帮忙吗??

最佳答案

来自 Axios Git:Unfortunately, I think this boils down to one of the dreaded CORS issues that developers often face. 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

其他有用的链接:cannot get cross-site POST to work , can not make post request ( cross domain ) .基本上这是一个浏览器安全问题而不是 Axios。他们不打算解决这个问题:要么选择另一个库,要么从后端处理它。请注意,使用 Chrome 中的安全禁用选项,该请求有效。

关于javascript - 预检响应在 axios 中没有 HTTP ok 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52370004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com