gpt4 book ai didi

javascript - 公理 : Request header field Access-Control-Allow-Methods is not allowed by Access-Control-Allow-Headers in preflight respones

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:11:41 29 4
gpt4 key购买 nike

我正在尝试从 onesignal api 发送 POST 请求

代码

axios({
method: 'post',
url: 'https://onesignal.com/api/v1/notifications',
headers: {
'Authorization': 'Basic NTRjZDY1O....',
'Content-type': 'application/json; charset=utf-8',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods': 'POST',
'Access-Control-Allow-Headers':'*',
'cache-control': 'no-cache'
},
data: {
"app_id": "8e86143e-00.......",
"contents": {
"en": "test api"
},
"included_segments": [
"All"
]
}
}).catch(function (error) {
if (error.response) {
console.log('error-response-data-'+error.response.data);
console.log('error-response-status-'+error.response.status);
console.log('error-response-headers-'+error.response.headers);
} else if (error.request) {
console.log('error-request-'+error.request);
} else {
console.log('Error', error.message);
}
});

错误输出

XMLHttpRequest cannot load https://onesignal.com/api/v1/notifications Request header field Access-Control-Request-Methods is not allowed by Access-Control-Allow-Headers in preflight response

error log

会修复它,但它没有。有没有人知道关于这个错误和/或我该如何修复它的任何信息?
我正在使用 firebase 托管

最佳答案

CORS 应在服务器端 启用以访问 API

关于javascript - 公理 : Request header field Access-Control-Allow-Methods is not allowed by Access-Control-Allow-Headers in preflight respones,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44818038/

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