firebase - 发送 Firebase 通知时,Axios 发布请求返回 403
问题描述
嗨,我正在尝试使用 firebase post 方法向我的应用程序发送通知,它在邮递员中工作正常,但是当我尝试在我的应用程序中执行 post 方法时,它返回 403。我尝试实现另一个 get 请求,它工作正常,所以 axios 设置没有问题。
export const postData = function (url, payload) {
return AXIOS.post(url, payload, config);
};
let config = {
headers: {
'Content-Type': 'application/json',
"Authorization" : "key= *****myKey****"
}
};
这是我的帖子方法
let body = {
"to": "******myTokeb*******",
"notification": {
"title": "Title here",
"body": "R(body)",
"mutable_content": true,
"sound": "Tri-tone"
}
};
postData("http://fcm.googleapis.com/fcm/send",body).then((d)=>{
console.log("d",d)
}).catch((e)=>{
console.log("e",e);
});
错误
Error: Request failed with status code 403
at createError (D:\projects\fiver\Roeyat\node_modules\axios\lib\core\createError.js:16)
at settle (D:\projects\fiver\Roeyat\node_modules\axios\lib\core\settle.js:17)
at EventTarget.handleLoad (D:\projects\fiver\Roeyat\node_modules\axios\lib\adapters\xhr.js:61)
at EventTarget.dispatchEvent (D:\projects\fiver\Roeyat\node_modules\event-target-shim\dist\event-target-shim.js:818)
at EventTarget.setReadyState (D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:567)
at EventTarget.__didCompleteResponse (D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:389)
at D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:502
at RCTDeviceEventEmitter.emit (D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189)
at MessageQueue.__callFunction (D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:425)
at D:\projects\fiver\Roeyat\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112
解决方案
在 postData 中使用 HTTPS 就可以了!
推荐阅读
- python - 我正在尝试解析 JSON 文件并将数据保存为我制作的自定义对象的属性
- amazon-web-services - 自引用 aws 安全组
- mysql - Mysql 数据库同步
- c# - 如何将 Observablecollection 绑定到 GridView?
- opencv - HoughCircles 正在返回错误的圆圈
- mongodb - 复杂对象的聚合
- javascript - 量角器随机警报框“错误:找不到 jQuery。”
- go - 如何协调 Rob Pike 的词法扫描演讲中 stateFn 和 errorf 的签名不匹配?
- android - 更改 InAppBrowser for iOS 的初始缩放
- javascript - Vue.js 从数组中添加类