C2dm Error=missingregistration I Already Put Registration_id To Request
i am working to sent a push message to android phone from my asp.net project and i already put register_id in my code but i handle an error Missing registration, i didnt understand
Solution 1:
Can try this code. I think the problem comes from url and request parameters.
publicvoidSendMessage(string registrationId, string data, string sAuth)
{
stringcollapseKey= Guid.NewGuid().ToString("n");
ServicePointManager.ServerCertificateValidationCallback += newRemoteCertificateValidationCallback(ValidateRemoteCertificate);
stringurl="https://android.apis.google.com/c2dm/send";
stringparams= HttpUtility.UrlEncode("registration_id=" + registrationId + "&collapse_key=" + collapseKey + "&data.payload=" + data);
HttpWebRequestrequest= (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.Headers.Add("Authorization", "GoogleLogin auth=" + sAuth);
//request.ContentLength = 0; ASCIIEncodingencoding=newASCIIEncoding();
byte[] buffer = encoding.GetBytes(params);
StreamnewStream= request.GetRequestStream();
newStream.Write(buffer, 0, buffer.Length);
newStream.Close();
//Reading return Responsetry
{
HttpWebResponseresponse= (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
StreamresStream= response.GetResponseStream();
StreamReadersr=newStreamReader(resStream);
stringvalue= sr.ReadToEnd().ToString();
Label1.Text = value;
//Response.Write(sr.ReadToEnd());
sr.Close();
resStream.Close();
}
}
catch (Exception ex)
{
throw (ex);
}
}
Solution 2:
If it's first time running your application on your device, then you have to handle first registration id. More details can be found here : http://code.google.com/android/c2dm/index.html
If it's not the case, then you have to take in consideration this issue: "The C2DM server periodically refreshes registration IDs." Witch means that you have to handle each refresh of your registration id.
Hope it helps.
Solution 3:
İ solve the problem like this;
HttpWebRequestrequest= (HttpWebRequest)WebRequest.Create("https://android.clients.google.com/c2dm/send");
request.Method = "POST";
request.KeepAlive = false;
NameValueCollectionpostFieldNameValue=newNameValueCollection();
postFieldNameValue.Add("registration_id", registrationId);
postFieldNameValue.Add("collapse_key", "1");
postFieldNameValue.Add("delay_while_idle", "0");
postFieldNameValue.Add("data.message", message);
stringpostData= GetPostStringFrom(postFieldNameValue);
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
request.ContentLength = byteArray.Length;
request.Headers.Add(HttpRequestHeader.Authorization, "GoogleLogin auth=" + authTokenString);
StreamdataStream= request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
//savas
ServicePointManager.ServerCertificateValidationCallback += delegate(
object
sender,
System.Security.Cryptography.X509Certificates.X509Certificate
pCertificate,
System.Security.Cryptography.X509Certificates.X509Chain pChain,
System.Net.Security.SslPolicyErrors pSSLPolicyErrors)
{
returntrue;
};
////***********WebResponseresponse= request.GetResponse();
HttpStatusCoderesponseCode= ((HttpWebResponse)response).StatusCode;
if (responseCode.Equals(HttpStatusCode.Unauthorized) || responseCode.Equals(HttpStatusCode.Forbidden))
{
Console.WriteLine("Unauthorized - need new token");
}
elseif (!responseCode.Equals(HttpStatusCode.OK))
{
Console.WriteLine("Response from web service not OK :");
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
}
StreamReaderreader=newStreamReader(response.GetResponseStream());
stringresponseLine= reader.ReadLine();
reader.Close();
Solution 4:
In this method SendMessage(string registrationId, string data, string sAuth)
not get notification in Andriod Device and No any error
Message , What to do ?
Post a Comment for "C2dm Error=missingregistration I Already Put Registration_id To Request"