Google chrome WebPushError:收到意外的响应代码
我正在使用以下简单代码尝试发送web通知:Google chrome WebPushError:收到意外的响应代码,google-chrome,push-notification,web-push,Google Chrome,Push Notification,Web Push,我正在使用以下简单代码尝试发送web通知: var webPush = require('web-push'); var pushSubscription = {"endpoint":"https://fcm.googleapis.com/fcm/send/f_JrbJx-214:APA91bEYIUbZOfNr6rgUs....UYhzxqco8yABlb8qZd", "keys": {"p256dh":&
var webPush = require('web-push');
var pushSubscription = {"endpoint":"https://fcm.googleapis.com/fcm/send/f_JrbJx-214:APA91bEYIUbZOfNr6rgUs....UYhzxqco8yABlb8qZd",
"keys": {"p256dh":"BPKXcfihQRFZbgm.....r0e0fXKP4QqZgaRk0P525orL8jpkjoJAOGNUrVtWbRg", "auth":"5EZPgD....XY4dTqg"}};
var payload = 'Here is a payload!';
var options = {
gcmAPIKey:'BHUkkdHG1C.....qgp8d5d9NOt5JrMXYRcc',
TTL: 60
};
webPush.sendNotification(
pushSubscription,
payload,
options
).catch(function(e) {
console.log(e);
});
我从浏览器的注册中获取了gcmAPIKey和用户信息。
但我始终收到:
{WebPushError:收到意外的响应代码
在IncomingMessage上。(/var/www/html/websockets/node_modules/web push/src/web push lib.js:298:20)
在emitNone(events.js:91:20)
在IncomingMessage.emit(events.js:185:7)
在endReadableNT(_stream_readable.js:978:12)
at _combinedTickCallback(内部/流程/下一步_tick.js:80:11)
在进程中。_tickCallback(internal/process/next_tick.js:104:9)名称:“WebPushError”,消息:“收到意外响应代码”,
状态代码:401,标题:{'content type':'text/plain;
字符集=utf-8',
“x-content-type-options”:“nosniff”,
“x-frame-options”:“SAMEORIGIN”,
“x-xss-protection”:“0”,
日期:2021年5月1日星期六16:17:08 GMT,
“内容长度”:“40”,
“alt svc”:“h3-29=“:443”;ma=2592000,h3-T051=“:443”;ma=2592000,h3-Q050=“:443”;ma=2592000,h3-Q046=“:443”;
ma=2592000,h3-Q043=“:443”;ma=2592000,quic=“:443”;ma=2592000;
v=“46,43”,
连接:'close'},必须指定正文:'authorization header.\n',终结点:
'https://fcm.googleapis.com/fcm/send/f_JrbJx-214:APA91bEYIUbZOfNr6rgUsU-3Fxf1ri8SyFUYhzxqco8yABlb8qZd'
}
然而,如果我在同一台服务器上执行它,我会得到更好的结果:
{WebPushError:收到意外的响应代码
在IncomingMessage上。(/var/www/html/pizzoMarinellaFS.inarrivo.net/node_modules/web push/src/web push lib.js:347:20)
在emitNone(events.js:91:20)
在IncomingMessage.emit(events.js:185:7)
在endReadableNT(_stream_readable.js:978:12)
at _combinedTickCallback(内部/流程/下一步_tick.js:80:11)
在进程中。_tickCallback(internal/process/next_tick.js:104:9)名称:“WebPushError”,消息:“收到意外响应代码”,
状态代码:403,标题:{'content type':'text/plain;
字符集=utf-8',
“x-content-type-options”:“nosniff”,
“x-frame-options”:“SAMEORIGIN”,
“x-xss-protection”:“0”,
日期:“2021年5月1日星期六16:31:45 GMT”,
“内容长度”:“29”,
“alt svc”:“h3-29=“:443”;ma=2592000,h3-T051=“:443”;ma=2592000,h3-Q050=“:443”;ma=2592000,h3-Q046=“:443”;
ma=2592000,h3-Q043=“:443”;ma=2592000,quic=“:443”;ma=2592000;
v=“46,43”,
连接:'close'},正文:'sender未通过身份验证。\n',终结点:
'https://fcm.googleapis.com/fcm/send/f_JrbJx-214:APA91bEYIUbZOfNr6rgUsU-3Fxf1ri8SyFUYhzxqco8yABlb8qZd'
}
更糟糕的是,如果你在谷歌文档中挖掘,你会完全迷失方向,显然你不得不用另一种方式去做,但会得到同样的错误