google Cloud Messaging Push notification

后端 未结 3 2030
时光说笑
时光说笑 2020-12-31 05:23

Can I use POSTMAN client on Google Chrome to send payload message to GCM server for testing purpose. Secondly if yes, what is the header and url parameter to be sent.

3条回答
  •  情深已故
    2020-12-31 05:57

    Just for the record and to complete the nice answer from @Alexandru Rosianu the GCM endpoint changed a while ago and it is suggested to use the new one. Here is an example taken from the official docs:

    Authentication

    To send a message, the application server issues a POST request. For example:

    https://gcm-http.googleapis.com/gcm/send
    

    A message request is made of 2 parts: HTTP header and HTTP body.

    The HTTP header must contain the following headers:

    • Authorization: key=YOUR_API_KEY
    • Content-Type: application/json for JSON; application/x-www-form-urlencoded;charset=UTF-8 for plain text. If Content-Type is omitted, the format is assumed to be plain text.

    For example:

    Content-Type:application/json
    Authorization:key=YOUR_API_KEY
    
    {
      "notification": {
          "title": "Portugal vs. Denmark",
          "text": "5 to 1"
      },
      "to" : "bk3RNwTe3H0:CI2k_H..."
    }
    

    The HTTP body content depends on whether you're using JSON or plain text. See the Server Reference for a list of all the parameters your JSON or plain text message can contain.

    Example using Curl:

    # curl --header "Authorization: key=YOUR_API_KEY" \
           --header Content-Type:"application/json" \
           https://gcm-http.googleapis.com/gcm/send \
           -d "{\"notification\": { \"title\": \"Portugal vs. Denmark\"," \
              "\"text\": \"5 to 1\" }, \"to\" : \"bk3RNwTe3H0:CI2k_H...\" }"
    

提交回复
热议问题