我已经完成了以下单一主题发送工作的通知:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["FirebaseAPI"]);
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header
client.DefaultRequestHeaders
.Authorization = new AuthenticationHeaderValue("key", "=" + ConfigurationManager.AppSettings["projectKey"]);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "relativeAddress");
//How to Send more Id's loop it with the array
var data = new
{
to = string.Concat("/topics/", 121),
notification = new
{
body = "test",
title = "FIRE alert"
}
};
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(data);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");//CONTENT-TYPE header
var resultArray = client.PostAsync("send", request.Content);
return resultArray.Result.Content.ReadAsStringAsync();