2017-01-17 3 views
0

Versuchen, eine Nachricht von meinem Server zu einem Web-Client, mit Webpush, mit diesem in Nodejs auf dem Server.Nodejs Web-Push Chrome Push-Benachrichtigung

webpush.sendNotification(body, 'Your Push Payload Text').then(console.log); 

Körper ein String mit den params ist erforderlich nach: https://github.com/web-push-libs/web-push

{"endpoint":"https://android.googleapis.com/gcm/send/eeXCuiNccV4:APA91bEC-ddg6Iy9OUjtDHzcjFd30cBM_6etyclYe63FrBP_UTCOA_oCwwDhrw-ILp1VqjdQD34X-G4WQ4xNUKnafTz4mGJZcppOsp-_HRNUHRgKXaAdppgClo2JsDAXZQjqxdGd0wq3","keys":{"p256dh":"BE3z-LbXeW65M6xdFhkhbFY9tj_re7RjEIUZDBPOslT1MqIG7-vaxHoUeZY3JOgJ_EaLa1eoifzNX3mno2PgCNc=","auth":"ZYov_VdiE2KZU65wpJWi8Q=="}} 

diesen Fehler:

{ WebPushError: Received unexpected response code 
12:42 AM 
    at IncomingMessage.<anonymous> (/app/node_modules/web-push/src/web-push-lib.js:274:20) 
12:42 AM 
    at emitNone (events.js:91:20) 
12:42 AM 
    at IncomingMessage.emit (events.js:185:7) 
12:42 AM 
    at endReadableNT (_stream_readable.js:974:12) 
12:42 AM 
    at _combinedTickCallback (internal/process/next_tick.js:74:11) 
12:42 AM 
    at process._tickCallback (internal/process/next_tick.js:98:9) 
12:42 AM 
    name: 'WebPushError', 
12:42 AM 
    message: 'Received unexpected response code', 
12:42 AM 
    statusCode: 400, 
12:42 AM 
    headers: 
12:42 AM 
    { 'content-type': 'text/html; charset=UTF-8', 
12:42 AM 
    date: 'Tue, 17 Jan 2017 06:42:38 GMT', 
12:42 AM 
    expires: 'Tue, 17 Jan 2017 06:42:38 GMT', 
12:42 AM 
    'cache-control': 'private, max-age=0', 
12:42 AM 
    'x-content-type-options': 'nosniff', 
12:42 AM 
    'x-frame-options': 'SAMEORIGIN', 
12:42 AM 
    'x-xss-protection': '1; mode=block', 
12:42 AM 
    server: 'GSE', 
12:42 AM 
    'alt-svc': 'quic=":443"; ma=2592000; v="35,34"', 
12:42 AM 
    'accept-ranges': 'none', 
12:42 AM 
    vary: 'Accept-Encoding', 
12:42 AM 
    connection: 'close' }, 
12:42 AM 
    body: '<HTML>\n<HEAD>\n<TITLE>UnauthorizedRegistration</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>UnauthorizedRegistration</H1>\n<H2>Error 400</H2>\n</BODY>\n</HTML>\n', 
12:42 AM 
    endpoint: 'https://android.googleapis.com/gcm/send/eeXCuiNccV4:APA91bEC-ddg6Iy9OUjtDHzcjFd30cBM_6etyclYe63FrBP_UTCOA_oCwwDhrw-ILp1VqjdQD34X-G4WQ4xNUKnafTz4mGJZcppOsp-_HRNUHRgKXaAdppgClo2JsDAXZQjqxdGd0wq3' } 
+0

Können Sie zeigen uns Ihre 'body' Variable? – Marco

+0

Funktioniert es in Firefox? – Marco

+0

Irgendein Erfolg? ... Ich steckte bei der gleichen Frage :(... (http://stackoverflow.com/questions/41870838/webpusherror-and-unauthorisierteregistration-when-try-to-send-push-notification-to) –

Antwort

0

Sie erhalten einen 400 Bad Request, stellen Sie sicher, dass Ihre VAPID-Schlüssel stimmen überein.

Der Server sollte sowohl den öffentlichen Schlüssel als auch den privaten Schlüssel enthalten, und die App sollte nur den öffentlichen Schlüssel enthalten.

Stellen Sie sicher, dass Sie das Schlüsselpaar nur einmal generieren.

können Sie auf dieser Seite ein Schlüsselpaar generieren: https://web-push-codelab.glitch.me/