Click here to Skip to main content
14,330,541 members
Rate this:
Please Sign up or sign in to vote.
See more:
hello all
i try to send cloud message to all devices android in my project ,, i try this using firebase and it work fine :)

but when i use c# code behind asp web application ,,, the result always seen as message id XXXXX
and i dont revive any notification :?

this is my code below ,,, plz help me :)

What I have tried:

WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
           tRequest.Method = "post";
           //serverKey - Key from Firebase cloud messaging server
           tRequest.Headers.Add(string.Format("Authorization: key={0}", "AI-------------------"));
           //Sender Id - From firebase project setting
           tRequest.Headers.Add(string.Format("Sender: id={0}", "----------"));
           tRequest.ContentType = "application/json";
           var payload = new
           {
               to = "/topics/all",
               notification = new
               {
                   title = "body",
                   body = "title",
                   sound = "Enabled"
               }

           };

           string postbody = JsonConvert.SerializeObject(payload).ToString();
           Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
           tRequest.ContentLength = byteArray.Length;
           using (Stream dataStream = tRequest.GetRequestStream())
           {
               dataStream.Write(byteArray, 0, byteArray.Length);
               using (WebResponse tResponse = tRequest.GetResponse())
               {
                   using (Stream dataStreamResponse = tResponse.GetResponseStream())
                   {
                       if (dataStreamResponse != null) using (StreamReader tReader = new StreamReader(dataStreamResponse))
                           {
                               String sResponseFromServer = tReader.ReadToEnd();
                               //result.Response = sResponseFromServer;


                           }
                   }
               }
           }
       }
Posted
Updated 8-Oct-19 11:52am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100