[英]send notification through c# WebApi to android using FCM
var webAddr = "https://fcm.googleapis.com/fcm/send";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add("Authorization:key=" + "My application ID");
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"to\": \"/topics/news\",\"data\": {\"message\": \"This is a Firebase Cloud Messaging Topic Message!\",}}";
streamWriter.Write(json);
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
这是我正在尝试但出现错误
System.dll中发生了'System.Net.WebException'类型的未处理异常
附加信息:远程服务器返回错误:(401)未经授权。
如下更改有效载荷,它将正常工作{“ to”:这是您的令牌“,”通知“:{” body“:”新消息新消息ew ESSAGE新消息新MW技术“,” title“:” Tesing596“ ,“ icon”:“ myicon”,“ sound”:mySound“,” click_action“:” android.PS“}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.