gonzaloaune / GCMPushPlugin

Push notifications for Cordova (GCM & Native support)
MIT License
37 stars 20 forks source link

call curl from webapi #37

Open mohanoorani opened 6 years ago

mohanoorani commented 6 years ago

how to call curl --header "Authorization: key=SERVER_API_KEY" \ --header Content-Type:"application/json" \ https://gcm-http.googleapis.com/gcm/send \ -d "{ \"data\" : { \"title\" : \"MyCoolApp\", \"text\" : \"MessageText\", \"extra\":{\"url\":\"someurl.js\"}}, \"to\" : \"$DEVICE_TOKEN\" }" FROM WebApi ??

mohanoorani commented 6 years ago

finaly find: in vb

Dim stringregIds As String = Nothing

        stringregIds = ""

        Try
            Dim GoogleAppID As String = ""
            Dim SENDER_ID = ""
            Dim value = "Hello"
            Dim tRequest As WebRequest
            tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send")
            tRequest.Method = "post"
            tRequest.ContentType = "application/json"
            tRequest.Headers.Add(String.Format("Authorization: key={0}", GoogleAppID))
            tRequest.Headers.Add(String.Format("Sender: id={0}", SENDER_ID))
            Dim postData As String = "{""collapse_key"":""score_update""," &
                                      """data"": { ""title"" :""Hello Word!"" , ""text"" :""text data!"",""extra"":{""url"":""noorani""}}," &
                                      """registration_ids"":[""" & stringregIds & """]}"
            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 StreamReader = New StreamReader(dataStream)
            Dim sResponseFromServer As String = tReader.ReadToEnd()
            Dim httpResponse As HttpWebResponse = CType(tResponse, HttpWebResponse)
            Dim statusCode As String = httpResponse.StatusCode.ToString()
            tReader.Close()
            dataStream.Close()
            tResponse.Close()
        Catch ex As Exception
            Dim x = ex
        End Try