> private JSONObject doJSONRequest(JSONObject jsonRequest,String Server) > { > HttpClient httpClient = new DefaultHttpClient(); > HttpPost request = new HttpPost(Server); > JSONObject jsonResponse = null; > > HttpResponse response = null; > String responseString = null; > JSONEntity entity = null; > > try > { > entity = new JSONEntity(jsonRequest); > } > catch (UnsupportedEncodingException e) > { > e.printStackTrace(); > } > > > request.setEntity(entity); > > > try > { > response = httpClient.execute(request); > responseString = EntityUtils.toString(response.getEntity()).trim(); > jsonResponse = new JSONObject(responseString); > } > catch (Exception ex) > { > ex.printStackTrace(); > } > return jsonResponse; > } > >>
>class JSONEntity extends StringEntity > { > public JSONEntity(JSONObject jsonObject) throws UnsupportedEncodingException > { > super(jsonObject.toString()); > } > > public Header getContentType() > { > return new BasicHeader("Content-Type", "application/json"); > } > } >