【发布时间】:2017-08-06 17:19:47
【问题描述】:
Firebase Cloud Messaging Server api 给出预检错误
$http({
method: 'POST',
url: 'https://fcm.googleapis.com/fcm/send',
headers: {
'Content-Type': 'application/json',
'Authorization': 'key=AIzaSyAZ-uI5....'
},
data: notificationData
}).then(function successCallback(response) {
console.log('notification sent')
}, function errorCallback(response) {
console.log('failed to send notification')
});
var notificationData = {
"to": "dR3179CIBdk:APA91bGqvNV0a9x0khUn2rX3c403CsezB9UjPyVsmnGQXMsxruo7r8N2lravIhx6lTG_FLXwXRposoxxcSpb5Rnj84lN0o2B-a2_tzxWkdc40HlEb0kNVC25Y3V3-d2c6WUHOeNo3_UM",
"data": {
"productid": '57039b3ae4b07b473966ec8c',
"title": "Off Upto 70% hello.com",
"flashSaleId": "58c2ae6038d991a47c27asdw"
},
"notification": {
"sound": "default",
"title": "Off Upto 70% Olivetheory.com",
"body": "Heavy Discounts on betsheets,Chairs,Beds,Pillows"
}
}
丑陋的预检错误
XMLHttpRequest 无法加载 https://fcm.googleapis.com/fcm/send。对预检请求的响应未通过访问控制检查:响应中“Access-Control-Allow-Credentials”标头的值为“”,当请求的凭据模式为“包含”时,该值必须为“真”。因此,Origin 'http://localhost:8080' 不允许访问。 XMLHttpRequest 发起的请求的凭证模式由 withCredentials 属性控制。
注意:我不想禁用 chrome 安全性。
不知道自己做错了什么
【问题讨论】:
标签: angularjs firebase xmlhttprequest cors firebase-cloud-messaging