TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Basit Khan
NA
336
121.6k
How to send GCM notification in javascript.
Dec 23 2016 11:22 AM
Hi,
How to send GCM notification in javascript.
I did in vb.net and it successfully sent with below code.
i want to convert below code or do it in javascript.
Private Sub Frm_SendNotification()
RegId = "xxxxx"
ApplicationID = "xxxxx"
SENDER_ID = "xxxx"
Dim value = TextBox1.Text
'message text box
Dim tRequest As WebRequest
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))
'Data post to the Server
'Dim postData As String = (Convert.ToString("collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=") & RegId) + ""
Dim postData As String = (Convert.ToString("data.message=" + value + "®istration_id=") & RegId) + ""
Console.WriteLine(postData)
Dim byteArray As [Byte]() = Encoding.UTF8.GetBytes(postData)
tRequest.ContentLength = byteArray.Length
Dim dataStream As Stream = tRequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim tResponse As WebResponse = tRequest.GetResponse()
dataStream = tResponse.GetResponseStream()
Dim tReader As New StreamReader(dataStream)
Dim sResponseFromServer As [String] = tReader.ReadToEnd()
'Get response from GCM server
Label1.Text = sResponseFromServer
'Assigning GCM response to Label text
tReader.Close()
dataStream.Close()
tResponse.Close()
End Sub
Thanks
Basit.
Reply
Answers (
1
)
How to get pop-up window's components?
How can i Change my Existing static website to wordpress?