我正在尝试使用azure服务器向我的C#代码发送消息到Android应用程序,但它不起作用,不确定azure阻止发送消息。这是我的代码片段:
public static void SendNoticeToFcmServer(string id, string title, string apiUrl,string key)
{
var jFcmData = new JObject();
var jData = new JObject();
jData.Add("body", title);
jData.Add("sound", "default");
jFcmData.Add("to", "/topics/" + id);
jFcmData.Add("priority", "high");
jFcmData.Add("notification", jData);
var url = new Uri(apiUrl);
using (var client = new HttpClient(new NativeMessageHandler()))
{
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.TryAddWithoutValidation(
"Authorization", "key=" + key);
Task.WaitAll(client.PostAsync(url,
new StringContent(jFcmData.ToString(), Encoding.UTF8, "application/json"))
.ContinueWith(response =>
{
}));
}
}