【发布时间】:2015-03-08 14:05:16
【问题描述】:
我可以使用 Google Chrome 上的 POSTMAN 客户端将有效负载消息发送到 GCM 服务器以进行测试吗? 其次如果是,要发送的header和url参数是什么。
【问题讨论】:
标签: android push-notification google-cloud-messaging
我可以使用 Google Chrome 上的 POSTMAN 客户端将有效负载消息发送到 GCM 服务器以进行测试吗? 其次如果是,要发送的header和url参数是什么。
【问题讨论】:
标签: android push-notification google-cloud-messaging
只是为了记录并完成@Alexandru Rosianu 的好答案,GCM 端点不久前发生了变化,建议使用新的端点。以下是取自官方文档的示例:
为了发送消息,应用服务器发出一个 POST 请求。例如:
https://gcm-http.googleapis.com/gcm/send
消息请求由两部分组成:HTTP 标头和 HTTP 正文。
HTTP 标头必须包含以下标头:
Authorization: key=YOUR_API_KEY Content-Type:application/json 用于 JSON; application/x-www-form-urlencoded;charset=UTF-8 用于纯文本。如果省略Content-Type,则假定格式为纯文本。例如:
Content-Type:application/json
Authorization:key=YOUR_API_KEY
{
"notification": {
"title": "Portugal vs. Denmark",
"text": "5 to 1"
},
"to" : "bk3RNwTe3H0:CI2k_H..."
}
HTTP 正文内容取决于您使用的是 JSON 还是纯文本。有关您的 JSON 或纯文本消息可以包含的所有参数的列表,请参阅 the Server Reference。
使用 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...\" }"
【讨论】:
是的,您可以使用 POSTMAN。
此 GCM 通知测试工具通过减少您每次在 POSTMAN 中输入的项目数量,极大地简化了服务器端测试 - http://techzog.com/development/gcm-notification-test-tool-android/
【讨论】:
是的,你可以。
网址:https://android.googleapis.com/gcm/send
标题:
正文(点击“原始”标签):
{
"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 是唯一必填字段,其他都是可选字段。
网址: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 是唯一必填字段,其他都是可选字段。
【讨论】:
key=ABC... 而不仅仅是ABC... 之前,我只是浪费了 2 个小时试图弄清楚为什么您的答案对我不起作用(401 未经授权的错误),也许这对其他人有帮助-现在很有魅力。