Yogesh Sharma

Yogesh Sharma

  • NA
  • 144
  • 46k

Display message delivered by GCM Server C# ASP.NET

Jul 6 2016 2:51 AM
Dear all friends,
 
after successfully sent message , i have got response as below that delivered by GCM Server.
 {
"multicast_id": 7818907016577379725,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1467785099062905%efe044b866d6cf16"
}
]
}
 
If i want to know what message delivered by GCM Server ??
Then what key or code should i conduct.. Pls. suggest me  
 
My Code as below :

string regId "xxxxxxxxxxx";

var applicationID = "xxxxxxxxxxx";

var SENDER_ID = "456789";

var value = txtmsg.Text; 

WebRequest tRequest;

tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");

tRequest.Method = "post";

tRequest.ContentType = "application/json";

tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));

tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));

string postData = "{\"data\": { \"message\" : " + "\"" + value + "\",\"time\": " + "\"" + System.DateTime.Now.ToString() + "\"},\"registration_ids\":[\"" + regId + "\"]}";

Byte[] byteArray = Encoding.UTF8.GetBytes(postData);

tRequest.ContentLength = byteArray.Length;

Stream dataStream = tRequest.GetRequestStream();

dataStream.Write(byteArray, 0, byteArray.Length);

dataStream.Close();

WebResponse tResponse = tRequest.GetResponse();

dataStream = tResponse.GetResponseStream();

StreamReader tReader = new StreamReader(dataStream);

String sResponseFromServer = tReader.ReadToEnd(); 

lblresponse.Text = sResponseFromServer; 

tReader.Close();

dataStream.Close();

tResponse.Close();

 
Thanks.
 
Yogesh. Sharma 

Answers (1)