[英]google Cloud Messaging Push notification
Can I use POSTMAN client on Google Chrome to send payload message to GCM server for testing purpose. 我可以在Google Chrome上使用POSTMAN客户端将有效负载消息发送到GCM服务器以进行测试。 Secondly if yes, what is the header and url parameter to be sent. 其次,如果是,则要发送的header和url参数是什么。
Yes, you can. 是的你可以。
URL: https://android.googleapis.com/gcm/send
网址: https://android.googleapis.com/gcm/send
: https://android.googleapis.com/gcm/send
Headers: 头:
Body (click on the 'raw' tab): 正文(点击'原始'标签):
{
"collapse_key": "score_update",
"time_to_live": 108,
"delay_while_idle": true,
"data": {
"score": "4x8",
"time": "15:16.2342"
},
"registration_ids":["4", "8", "15", "16", "23", "42"]
}
Note: registration_ids
is the only required field, all the others are optional. 注意: registration_ids
是唯一必填字段,所有其他字段都是可选字段。
URL: https://android.googleapis.com/gcm/send
网址: https://android.googleapis.com/gcm/send
: https://android.googleapis.com/gcm/send
Headers: 头:
Body (click on the 'x-www-form-urlencoded' tab): 正文(点击'x-www-form-urlencoded'标签):
collapse_key=score_update
time_to_live=108
delay_while_idle=1
data.score=4x8
data.time=15:16.2342
registration_id=42
Note: registration_id
is the only required field, all the others are optional. 注意: registration_id
是唯一必填字段,其他所有字段都是可选字段。
Source: https://developer.android.com/google/gcm/http.html 资料来源: https : //developer.android.com/google/gcm/http.html
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. 只是为了记录并完成@Alexandru Rosianu的好答案,GCM端点改变了一段时间,建议使用新的。 Here is an example taken from the official docs: 以下是官方文档中的示例:
To send a message, the application server issues a POST request. 要发送消息,应用程序服务器会发出POST请求。 For example: 例如:
https://gcm-http.googleapis.com/gcm/send
A message request is made of 2 parts: HTTP header and HTTP body. 消息请求由两部分组成:HTTP标头和HTTP主体。
The HTTP header must contain the following headers: HTTP标头必须包含以下标头:
Authorization
: key=YOUR_API_KEY Authorization
:key = YOUR_API_KEY Content-Type
: application/json
for JSON; Content-Type
:JSON的application/json
; application/x-www-form-urlencoded;charset=UTF-8
for plain text. application/x-www-form-urlencoded;charset=UTF-8
用于纯文本。 If Content-Type
is omitted, the format is assumed to be plain text. 如果省略Content-Type
,则假定格式为纯文本。 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. HTTP正文内容取决于您使用的是JSON还是纯文本。 See the Server Reference for a list of all the parameters your JSON or plain text message can contain. 有关JSON或纯文本消息可以包含的所有参数的列表,请参阅服务器参考 。
Example using Curl: 使用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...\" }"
Yes, you can use POSTMAN. 是的,你可以使用POSTMAN。
This GCM Notification Test Tool simplifies the server side testing immensely by reducing the number of items you enter in POSTMAN everytime - http://techzog.com/development/gcm-notification-test-tool-android/ 此GCM通知测试工具通过减少您每次在POSTMAN中输入的项目数量,极大地简化了服务器端测试 - http://techzog.com/development/gcm-notification-test-tool-android/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.