我可以使用Google Chrome上的 POSTMAN客户端来发送有效载荷消息以测试GCM服务器吗?如果可以,需要发送哪些头部和URL参数。
我可以使用Google Chrome上的 POSTMAN客户端来发送有效载荷消息以测试GCM服务器吗?如果可以,需要发送哪些头部和URL参数。
可以的。
URL: https://android.googleapis.com/gcm/send
Headers:
Body(点击“原始”选项卡):
{
"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"]
}
注意:registration_ids
是唯一必填字段,其他字段均为可选。
URL:https://android.googleapis.com/gcm/send
头信息:
正文(点击“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
注意:registration_id
是唯一必需的字段,其他所有字段都是可选的。
仅供记录和补充@Alexandru Rosianu的优秀回答,GCM端点已经改变,建议使用新的端点。以下是官方文档中的一个示例:
为了发送消息,应用服务器发出POST请求。例如:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=YOUR_API_KEY
{
"notification": {
"title": "Portugal vs. Denmark",
"text": "5 to 1"
},
"to" : "bk3RNwTe3H0:CI2k_H..."
}
# 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...\" }"
是的,您可以使用POSTMAN。
这个GCM通知测试工具通过减少您在每次使用POSTMAN时输入的条目数量,极大地简化了服务器端测试 - http://techzog.com/development/gcm-notification-test-tool-android/
key=ABC...
,而不只是ABC...
。也许这能帮助别人——现在运作得很好。 - Mete