2017-09-05 153 views
0
 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.Net.WebException」未處理的異常發生在System.dll中發送通知到Android使用FCM

錯誤

附加信息:遠程服務器返回錯誤:(401)未經授權。

回答

0

更改有效載荷如下它將正常工作 {「to」:這是您的令牌「,」通知「:{」body「:」新消息新消息ew消息新消息新mw技術「,」標題「:」Tesing596「,」icon「:」myicon「,」sound「:mySound」,「click_action」:「android.PS」}}