I am new in Java programming. i have developed an android application which send a request to GCM server and in response its getting a registration id which i am send to my java server and on server i am storing it in database. Its working fine :)
For second part i have written http code in java server. with this code i am access the registration id from database and sending it to GCM server with a string message for for device. But i am getting error. my code for http client is here. please can some one help?
public static String REQUEST_URL = "https://android.googleapis.com/gcm/send";
private static String GCM_ID = "APA91bFEnZXT7YRTJm2d5NpbKcpJCuDwEIJjZmwYITIIWIOFIZHEtwYc8S3oN_Upe3RnSvUqcwmntIrMqaF8Vn04b_EZtvoDQMAqt21Zw9Sb9GhNXwVS70yDOjUyRohH7u1RmtTHRrkjaBUueIjS2gD1Uw1cQDJbQg";
/**
* @param args
*/
public static void main(String[] args) {
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("registration_id", GCM_ID));
formparams.add(new BasicNameValuePair("data", "this is data mesg"));
// UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams,
// "UTF-8");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(REQUEST_URL);
httpPost.setHeader("Authorization",
"key=AIzaSyBTgKVWevp0GwM5m2QAuF__39eEI0bclVA");
httpPost.setHeader("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
try {
httpPost.setEntity(new UrlEncodedFormEntity(formparams, "utf-8"));
httpclient.execute(httpPost);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}