我正在尝试通过POST请求向Firebase Cloud Messaging发送消息给Android设备。但是当我从POSTMAN执行发布请求时,服务器以成功响应200响应。
但是当我通过AJAX请求在JAVASCRIPT中做同样的事情时,我正在获取错误400。
如何解决这个问题?
url: - “https://fcm.googleapis.com/fcm/send”
Content-Type:“application / json”
授权:“key = mykey”
{
"to" : "/topics/global",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark"
}
}
如果我通过AJAX请求从javascript发送相同的数据,我会得到响应400.
mydata = {
"to" : "/topics/global",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark"
}
}
headers= {
"Content-Type": "application/json",
"Authorization": "key=AIzaSy....KC1Q",
}
$.post({
url: 'https://fcm.googleapis.com/fcm/send',
data: mydata,
success: function (e) {
console.log(e+ "SUCESS") ;
},
headers: headers
});
答案 0 :(得分:1)
请尝试将ajax
方法更改为:
$.ajax({
url: "https://fcm.googleapis.com/fcm/send",
data: mydata,
success:function(e){console.log(e)},
headers: {
"Content-Type":"application/json",
"Authorization":"key=mykey"
}
})