推送通知错误 - 缺少注册
Posted
技术标签:
【中文标题】推送通知错误 - 缺少注册【英文标题】:Push notifications Error - Missing Registration 【发布时间】:2014-04-29 13:19:48 【问题描述】:我已通过 GCM 使用 ASP.net C# 向安卓手机发送推送通知。
但我尝试了不同类型的代码,但所有 arr 都返回 Missing Registration 错误,所以请帮助我。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PushNotification;
namespace TestandroidPush
public partial class Test : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
Main();
private void Main()
AndroidGCMPushNotification apnGCM = new AndroidGCMPushNotification();
string strResponse = apnGCM.SendNotification(device id, "Test Push");
cs 文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Text;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Collections.Specialized;
public class AndroidGCMPushNotification
public AndroidGCMPushNotification()
//
// TODO: Add constructor logic here
//
public string SendNotification(string deviceId, string message)
string GoogleAppID = "GoogleAppID";
var SENDER_ID = "sender id";
var value = message;
WebRequest tRequest;
tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key=0", GoogleAppID));
tRequest.Headers.Add(string.Format("Sender: id=0", SENDER_ID));
string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" + deviceId + "";
Console.WriteLine(postData);
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
return sResponseFromServer;
【问题讨论】:
哼哼开始你的android代码很脏,请缩进和所有x) @Yume117: 它的 c# 代码 使用github.com/Redth/PushSharp '®istration_id' - 这是您的帖子或实际代码中的错字吗? 【参考方案1】:当您未能在请求中包含注册 ID 时,GCM 会返回MissingRegistration
。
对于您使用的纯文本请求(基于您的 application/x-www-form-urlencoded;charset=UTF-8
内容类型),注册 ID 应作为 &registration_id=your_registration_id
而不是 ®istration_id=
作为您发布的代码中的传递。
【讨论】:
以上是关于推送通知错误 - 缺少注册的主要内容,如果未能解决你的问题,请参考以下文章