首页 > 解决方案 > 发送 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

标签: firebasereact-nativeaxios

解决方案


在 postData 中使用 HTTPS 就可以了!


推荐阅读