期間web-push與GCM和鍍鉻的發展。我最近遇到了這個問題,由於在GCM或一些改變雲的停機時間(幾個小時前還一切工作正常)網絡推未知的問題,WebPushError「收到意外的響應代碼」 400
我不知道這是否會發生...任何信息將不勝感激。
我的代碼
var payload = JSON.stringify({
title: 'notification title',
body: 'message body'
});
webPush.sendNotification(params.endpoint, {
userPublicKey: params.userPublicKey,
userAuth: params.userAuth,
payload: payload
}).then(function (res) {
// console.log of stuff
})
.catch(function(error){
console.log(error);
process.exit(1);
});
跟蹤:
{
WebPushError: Received unexpected response code
at IncomingMessage.<anonymous> (/var/www/***/pwa/node_modules/web-push /index.js:264:20)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:926:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
name: 'WebPushError',
message: 'Received unexpected response code',
statusCode: 400,
headers: {
'content-type': 'text/plain; charset=UTF-8',
date: 'Wed, 04 May 2016 11:35:13 GMT',
expires: 'Wed, 04 May 2016 11:35:13 GMT',
'cache-control': 'private, max-age=0',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1; mode=block',
server: 'GSE',
'alternate-protocol': '443:quic',
'alt-svc': 'quic=":443"; ma=2592000; v="33,32,31,30,29,28,27,26,25"',
'accept-ranges': 'none',
vary: 'Accept-Encoding',
connection: 'close'
},
body: 'JSON_PARSING_ERROR: Unexpected token END OF FILE at position 467.\n'
}
如果你不想陷入低層次的細節,我建議你使用像[pushpad-node](https://github.com/pushpad/pushpad-node)這樣的服務 – collimarco
你能告訴我們一個有效載荷的例子嗎? – Marco
@collimarco你的建議對我來說似乎很有趣。但令人遺憾的是,需要爲該項目製作一個專用的推送模塊...第三項服務將立即被拒絕:( –