我正在尝试从onesignal api发送POST请求
CODE
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无法加载https://onesignal.com/api/v1/notifications 请求标头字段不允许使用Access-Control-Request-Methods 预检响应中的Access-Control-Allow-Headers
会解决它,但事实并非如此。有没有人有关于此错误的信息和/或我如何解决它? 我正在使用firebase托管
答案 0 :(得分:2)
CORS 以访问API