android - Getting the response code 200 while sending message to gcm server but the result displays error -


i have created application server sends message gcm server via http post. after executing code response code of 200 result displayed error=missingregistration .

i not able understand why registration id missing. have obtained registration id of emulator creating google account on it. have verified project id , keys , have used gcm-server.jar create server. have tried using server key instead of browser key still getting same result.

here code of application server sends message through http post gcm server.

    package com.example.gcmserver;      import java.io.bufferedreader;     import java.io.ioexception;     import java.io.inputstreamreader;     import java.util.arraylist;     import java.util.list;      import org.apache.http.httpexception;     import org.apache.http.httprequest;     import org.apache.http.httprequestinterceptor;     import org.apache.http.httpresponse;     import org.apache.http.namevaluepair;     import org.apache.http.auth.authscope;     import org.apache.http.auth.authstate;     import org.apache.http.auth.credentials;     import org.apache.http.auth.usernamepasswordcredentials;     import org.apache.http.client.credentialsprovider;     import org.apache.http.client.entity.urlencodedformentity;     import org.apache.http.client.methods.httppost;     import org.apache.http.client.protocol.clientcontext;     import org.apache.http.impl.auth.basicscheme;     import org.apache.http.impl.client.defaulthttpclient;     import org.apache.http.message.basicnamevaluepair;     import org.apache.http.protocol.httpcontext;      public class server {         public static void main(string[] args) throws ioexception {              defaulthttpclient client = new defaulthttpclient();             client.getcredentialsprovider().setcredentials(authscope.any, new usernamepasswordcredentials("username", "password"));             client.addrequestinterceptor(new httprequestinterceptor() {           @override         public void process(httprequest arg0, httpcontext context)                 throws httpexception, ioexception {             // todo auto-generated method stub               authstate state = (authstate) context.getattribute(clientcontext.target_auth_state);                  if (state.getauthscheme() == null) {                      basicscheme scheme = new basicscheme();                      credentialsprovider credentialsprovider = (credentialsprovider) context.getattribute(clientcontext.creds_provider);                      credentials credentials = credentialsprovider.getcredentials(authscope.any);                      if (credentials == null) {                          throw new httpexception();                      }                      state.setauthscope(authscope.any);                      state.setauthscheme(scheme);                      state.setcredentials(credentials);         }}      }, 0);                      httppost httppost = new httppost("https://android.googleapis.com/gcm/send");                list<namevaluepair> urlparameters = new arraylist<namevaluepair>();               urlparameters.add(new basicnamevaluepair("data.registration id","apa91berscmbvv-dias7oka6nqlatuq1e8whuhjn54wcsfasiy3pslby2_dtsq7gjs_rxcouuptj8obnvnd55vbxjiwvwgxgj71orfw_0yp4uz9jgdtax5dy-dkhnk6tk2gefy50bdukebqornuo9cyfssw3aatqv4tjdkv4gywtui0viulisjm"));                urlparameters.add(new basicnamevaluepair("data.title", "e-pass application"));               urlparameters.add(new basicnamevaluepair("data.message", "your code 13133"));                 httppost.setheader("authorization",                       "key=mybrowserkey");               httppost.setheader("content-type",                       "application/x-www-form-urlencoded;charset=utf-8");               httppost.setheader("sender_id", "myprojectid");                httppost.setentity(new urlencodedformentity(urlparameters, "utf-8"));                httpresponse response = client.execute(httppost);               system.out.println("response code : "                            + response.getstatusline().getstatuscode());               system.out.println("getting contents of message");                bufferedreader rd = new bufferedreader(                       new inputstreamreader(response.getentity().getcontent()));                stringbuffer result = new stringbuffer();               string line = "";               while ((line = rd.readline()) != null) {                   result.append(line);               }                 system.out.println("the result is:"+result);     }     } 

i have referred link create server: trying http-post gcm java

thanks lot in advance help.

no need prefix registration id "data.". key-value pair should be: registration_ids, array containing registration id


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -