Attempting to send a message to Android devices through a POST request to Firebase Cloud Messaging. When using POSTMAN, the server responds with a success response 200.
However, when attempting the same operation with JavaScript using an AJAX request, I receive an error 400.
How can this issue be resolved?
Sent Data via POSTMAN:
URL:
Content-Type: application/json
Authorization: key=mykey
{
"to" : "/topics/global",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark"
}
}
JAVASCRIPT AJAX Request:
When sending the same data from JavaScript using an AJAX request, an error 400 is received.
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+ "SUCCESS") ;
},
headers: headers
});