相关疑难解决方法(0)

无法使用Google App Engine(GAE)连接到Google Cloud Messaging(GCM)服务器

我正在尝试为我的应用设置谷歌云消息,我正在为我的服务器使用Google App Engine.我有我的API密钥,但我似乎无法连接到谷歌云消息服务器.这是我的代码.

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://android.googleapis.com/gcm/send");
        try {

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("registration_id", regId));
            nameValuePairs.add(new BasicNameValuePair("data.message", messageText));    

            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            post.setHeader("Authorization", "key=*MY_API_KEY_HERE*");
            post.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");


            Header[] s=post.getAllHeaders();


            System.out.println("The header from the httpclient:");

            for(int i=0; i < s.length; i++){
            Header hd = s[i];

            System.out.println("Header Name: "+hd.getName()
                    +"       "+" Header Value: "+ hd.getValue());
            }


            HttpResponse response = client.execute(post);
            BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            String line = "";
            while ((line = rd.readLine()) != null) { …
Run Code Online (Sandbox Code Playgroud)

java google-app-engine google-cloud-messaging

7
推荐指数
1
解决办法
2384
查看次数