Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebPush {"Received unexpected response code"}

How to send notification using Webpush library. I was trying but its throws error msg like {"Received unexpected response code"}

****Now i have created web API to send notification & calling you through fiddler,but did n't get exception it's stuck somewhere here is my code sample****

public void Sendnotification()
        {
            try
            {
       WebPush.VapidDetails vapidKeys = apidHelper.GenerateVapidKeys();
         string subject =@"mailto:xyz.com";
         string publicKey = Convert.ToString(vapidKeys.PublicKey);
         string privateKey = Convert.ToString(vapidKeys.PrivateKey);

        var subscription = new PushSubscription(pushEndpoint, p256dh, auth);
        var vapidDetails = new VapidDetails(subject, publicKey, privateKey);

        client.SendNotification(subscription, "payload", vapidDetails);
            }
            catch (WebPushException e)
            {

            }
        }

I have configured Https enabled to call api using fidder. Please have look. also its throws error, it stuck somewhere enter image description here

now it got the error please have look it's showing error HTTP/1.1 410 NotRegistered enter image description here

See the full screen of Fiddler response error details

like image 337
Vineet Kumar Rai Avatar asked May 19 '26 14:05

Vineet Kumar Rai


1 Answers

If you are getting the error 410 (to check the error use fiddler to intercept the https call), probably what you have is an error in the subscription data of the user probably the keys stored in your database doesn't match the subscription in the browser an easy fix could be to re-subscribe and re-save the subscription data and try again.

to setup fiddler, you have to use it as a proxy visual studio to intercept the https calls and also you have to enable https decryption.

EDIT

you can set up fiddler just by adding this configuration in your web.config or app.config:

<system.net>
 <defaultProxy
  enabled = "true"
  useDefaultCredentials = "true">
 <proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888" usesystemdefault="false" />
 </defaultProxy>
 </system.net>

if in any case, you get unauthorized registration check this questions:

Web Push API Chrome, returning "Unauthorized Registration"

WebPushError and UnauthorizedRegistration when try to send push notification to Chrome and Opera, FF is OK

like image 186
pedrommuller Avatar answered May 22 '26 04:05

pedrommuller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!