I think the best way to get your work done is to use an HTTP message to do this, you need 5 things:
1) make a Json object: JSONObject jsonobj = new JSONObject(); //you need to fill this object JSONObject jsonobj = new JSONObject(); //you need to fill this object
2) Create an http client:
DefaultHttpClient httpclient = new DefaultHttpClient();
3) create an http response and an http request:
HttpResponse httpresponse; HttpPost httppostreq;
3) fill out your http-request:
httppostreq = new HttpPost(SERVER_URL);
4) attach the json object (the one you will send):
StringEntity se = new StringEntity(jsonobj.toString()); se.setContentType("application/json;charset=UTF-8"); httppostreq.setEntity(se);
5) to get the answer: httpresponse = httpclient.execute(httppostreq); //as a Json object httpresponse = httpclient.execute(httppostreq); //as a Json object
2 observations: you need to catch exceptions for exceptions, and always the http request must be executed in another thread.
source share