Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void send(string regId)
- {
- var applicationID = "xxxxxxxx";
- var SENDER_ID = "xxxxx";
- var value = txtMsg.Text;
- WebRequest tRequest;
- tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
- tRequest.Method = "post";
- tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
- tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
- tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
- // string postData = "{ 'registration_id': [ '" + regId + "' ], 'data': {'message': '" + txtMsg.Text + "'}}";
- string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" + regId + "";
- Console.WriteLine(postData);
- 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();
- lblStat.Text = sResponseFromServer;
- tReader.Close();
- dataStream.Close();
- tResponse.Close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement