Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hc As WebRequest
Dim collapseKey As String
Dim postData As String
' Dim postData1 As String
' Dim postData2 As String
Dim DeviceID As String = "799750522480"
Dim sCommand As String = "This is a Test"
Dim byteArray As Array
Dim dataStream As IO.Stream
hc = WebRequest.Create("https://android.googleapis.com/gcm/send")
hc.Method = "post"
hc.ContentType = "application/x-www-form-urlencoded"
hc.Headers.Add(String.Format("Authorization:Key={0}", "AIzaSyACz_BoIsLCn6TKUWdolrDlEa0-NsGqKWQ"))
'txtResult.Text = String.Format("Authorization: Key={0}", "AIzaSyACz_BoIsLCn6TKUWdolrDlEa0-NsGqKWQ")
collapseKey = Guid.NewGuid().ToString("n")
postData = String.Format("registration_id={0}&data.payload={1}&collapse_key{2}", DeviceID, sCommand, collapseKey) '&data.payload=&collpase_key=", DeviceID, sCommand, collapseKey)
'postData1 = String.Format("&data.payload=This is just a test")
' postData2 = ("&collapse_key=" & collapseKey)
'postData1 = String.Format(
' txtResult.Text = postData '+ postData1 + postData2
byteArray = Encoding.UTF8.GetBytes(postData)
hc.ContentLength = byteArray.Length
dataStream = hc.GetRequestStream
dataStream.Write(byteArray, 0, byteArray.Length)
' dataStream.Close()
Dim tResponse As WebResponse
tResponse = hc.GetResponse
dataStream = tResponse.GetResponseStream
Dim treader As StreamReader
treader = New StreamReader(dataStream)
Dim response As String
response = treader.ReadToEnd
txtResult.Text = response '& vbCrLf & postData + postData1 + postData2
treader.Close()
dataStream.Close()
tResponse.Close()
End Sub