我已经集成了firebase以在我的.NET应用程序中发送通知。在我的应用程序中,我使用 registration_ids 向多个ID发送通知,数据采用JSON格式。 这是我的代码
var webAddr = "https://fcm.googleapis.com/fcm/send";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, "key=*******);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = 0;
string[] deviceIds = new string[] { "fm1MWzVyRxA:APA91bFKTAUwCVJCYT1GbMB6dTK5DPAApuxY01yPJtPpnGwtHkavSWFm5SRVMQtCWrtfTH3pN_8mxEFU-o0TwgFtN-2JtLxn4DkMVYw80OnfWqhV93z72PR9rZgdGI77CulMoCWtUO1_", "fy79LobUOxg:APA91bGG7DUMhfO2gRPjINMS1Vfh_RdZdUJH5r_GKipHB50e6sc5J2pexo9-Xd1cfpJyAqAZjJ6ylMhKpHm75jPXyEtB2bH0Onqr6Ln0baIXxuWNxmHl7zXWNmWeoI9q-GP_FnlcI6AH" };
var datat = new
{
registration_ids = deviceIds,
notification = new
{
body = "Osama",
title = "AlBaami",
sound = "Enabled"
}
};
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(datat);
这是我的json数据
{"registration_ids":["fm1MWzVyRxA:APA91bFKTAUwCVJCYT1GbMB6dTK5DPAApuxY01yPJtPpnGwtHkavSWFm5SRVMQtCWrtfTH3pN_8mxEFU-o0TwgFtN-2JtLxn4DkMVYw80OnfWqhV93z72PR9rZgdGI77CulMoCWtUO1_","fy79LobUOxg:APA91bGG7DUMhfO2gRPjINMS1Vfh_RdZdUJH5r_GKipHB50e6sc5J2pexo9-Xd1cfpJyAqAZjJ6ylMhKpHm75jPXyEtB2bH0Onqr6Ln0baIXxuWNxmHl7zXWNmWeoI9q-GP_FnlcI6AH"],"notification":{"body":"Osama","title":"AlBaami","sound":"Enabled"}}
在这一行
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
我得到的回复显示错误消息= “The remote server returned an error: (400) Bad Request."
我也对json格式进行了调整,它是有效的,所以问题的可能解决方案应该是什么
答案 0 :(得分:-1)
在我的应用程序中,我可以使用至而非 registration_ids 成功发送通知。 此外,我使用了另一个标题:
Sender: id={server_id}
//Where server_id is the server_id that can be found in Firebase -> Settings -> Project Settings -> Cloud Messaging