大佬教程收集整理的这篇文章主要介绍了服务器上的推送通知发送失败,出现 401 错误,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发具有网络推送通知功能的 KaiOS 应用程序。
虽然以下代码在 Chrome 和当前的 Mozilla 上有效,但在 KaiOS 上失败。
NodeJs 代码:
const push = require('web-push');
const vapidKeys = {
publicKey: 'PUBliC_KEY',privateKey: 'PRIVATE_KEY',};
push.setvapidDetails(
'valID@email.com',vapidKeys.publicKey,vapidKeys.privateKey
);
const pushSub = {
endpoint: 'https://push.Kaiostech.com:8443/wpush/v2/gAAAAABgNqjxZulGGFU',keys: {
auth: 'AUTH',p256dh: 'P256dH',},};
KaiOS:
Failed to send notification WebPushError: Received unexpected response code
at Incomingmessage.<anonymous> (/node_modules/web-push/src/web-push-lib.Js:347:20)
at Incomingmessage.emit (events.Js:327:22)
at endReadableNT (_stream_readable.Js:1221:12)
at processticksAndRejections (internal/process/task_queues.Js:84:21) {
statusCode: 401,headers: {
date: 'Thu,25 Feb 2021 15:35:19 GMT','content-length': '15','content-type': 'text/plain; charset=utf-8',connection: 'close'
},body: '{"errno":"109"}',endpoint: 'https://push.Kaiostech.com:8443/wpush/v2/gAAAAABgNqjxZulGGFU-72vZJFv0avzqAZADWd7FSwZBINZ8AvsEkxAU2J3AFcs0e4aEUIYxi8aSzCCn8ihUgof_nfLGyR8VBprtzgZEABf14rSb9RgGgwxQiP6f2792pS0BcuawcerZbNstCotDYTXdNZ7jQvegfDHUEHvril1KeEeaMoi4nGk'
}
但是在 Mozilla(经过适当的关键更改)上,它的响应是成功的。在 Chrome 上也一样。
notification response: {
statusCode: 201,body: '',headers: {
'access-control-allow-headers': 'content-encoding,encryption,crypto-key,ttl,encryption-key,content-type,authorization','access-control-allow-methods': 'POST','access-control-allow-origin': '*','access-control-expose-headers': 'LOCATIOn,www-authenticate','content-type': 'text/HTML; charset=UTF-8',date: 'Wed,24 Feb 2021 20:38:35 GMT',LOCATIOn: 'https://updates.push.services.mozilla.com/m/gAAAAABgNrlLgRnDfpaVmZjc6eqnAxoXkaYkTT4nKCTI1ZIBt62hfu2l3XvGr0F8HfvW54etByCQNSX89ubyBjd2VtXOTPqfsiC4-IDBWol9q9GRwiBSgjFc2M5-avDmrRpq9eCAsxlgGCzp2sRYRqvVDAQBHa8GznLzKmDE87rWZM6ItMiLS8PN0jqiSZFymlqooeCK53QN',server: 'Nginx','Strict-transport-security': 'max-age=31536000;includeSubDomains',ttl: '2419200','content-length': '0',connection: 'Close'
}
}
这是客户服务工作者代码:
self.addEventListener('push',(event) => {
console.log('push event',event);
const title = event.data.text();
event.waitUntil(self.registration.showNotification(titlE));
});
任何想法,可能有什么问题?
push.sendNotification(pushSub,'Hello my name is me',{
contentEncoding: 'aesgcm'
})
.then(function (res) {
console.log('notification response: ',res);
})
.catch(function (err) {
console.error('failed to send notification',err);
});
https://github.com/web-push-libs/web-push/issues/603
,以上是大佬教程为你收集整理的服务器上的推送通知发送失败,出现 401 错误全部内容,希望文章能够帮你解决服务器上的推送通知发送失败,出现 401 错误所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。