如何在安卓系统中设置后台使用ASP.NET的推送通知机制
我想设置一个应用程序GCM,但后端有在ASP.net,请参阅一个完整的指南,如果可以。
服务器端和android端
发布于 2018-10-24 20:36:26
为了部分回答这个问题,服务器端可以用C#实现。以下链接记录了消息格式和一般方法。
http://developer.android.com/google/gcm/server.html
https://developer.android.com/google/gcm/http.html
https://developers.google.com/cloud-messaging/server-ref#table1
也就是说,可以按如下方式发送实际的推送消息。
var iReq = WebRequest.Create("https://android.googleapis.com/gcm/send");
iReq.Method = "post";
iReq.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
iReq.Headers.Add(String.Format("Authorization: key={0}", Key));
string iMsg;
// iMsg must be filled with the actual data to be sent
// and understood by the client
var PostData = Uri.EscapeUriString(PostData);
var byteArr = Encoding.UTF8.GetBytes(PostData);
iReq.ContentLength = byteArray.Length;
var DataStream = iReq.GetRequestStream();
DataStream.Write(byteArray, 0, byteArray.Length);
DataStream.Close();
string ServerResponse; // will contain the response to examine
HttpStatusCode StatusCode;
using (var iRes = iReq.GetResponse())
{
using (var iReader = new StreamReader(iRes.GetResponseStream()))
{
ServerResponse = iReader.ReadToEnd();
}
StatusCode = (iResponse as HttpWebResponse).StatusCode;
}https://stackoverflow.com/questions/52968890
复制相似问题