HTTP Post Request: Error 400, Firebase Topic Messaging

二次信任 提交于 2019-11-29 15:53:57

Error 400 means an Invalid JSON in your request:

Check that the JSON message is properly formatted and contains valid fields (for instance, making sure the right data type is passed in).

In your sendRequest, you missed a comma (,) between "news\" and \"data\" and a closing bracket (}):

String postJsonData = "{\"to\": \"/topics/news\"\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\"}";

which looks like this:

{"to": "/topics/news/""data":{"message":"...."}

Should be:

String postJsonData = "{\"to\": \"/topics/news\", \"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\"}}";

So that the JSON structure would be correct:

{"to": "/topics/news/",
 "data":{"message":"..."}
}

For those who are willing to use the authentication key in your application.

I suggest to encrypt the key manually by the SHA-1 of your application and the decrypt it at the time of runtime with the SHA-1 code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!