Thursday, May 3, 2012

post request in JSON




 private String getResponseData() throws Exception {
  String path = "";

  JSONObject jObjAssetDetails = new JSONObject();
  jObjAssetDetails.put("id", "5343377");// 671003");
  // jObjAssetDetails.put("id","671003");
  String strPostBody = jObjAssetDetails.toString();

  DefaultHttpClient httpClient = new DefaultHttpClient();
  HttpPost postMethod = new HttpPost(path);

  StringEntity sEntity;
  sEntity = new StringEntity(strPostBody, "UTF-8");
  postMethod.setEntity(sEntity);
  HttpResponse httpResponse = httpClient.execute(postMethod);

  InputStream ins = httpResponse.getEntity().getContent();

  GZIPInputStream data = new GZIPInputStream(ins);

  BufferedReader r = new BufferedReader(new InputStreamReader(data));

  StringBuilder total = new StringBuilder();
  String line;
  while ((line = r.readLine()) != null) {
   total.append(line);
  }
  Log.w("urloutput", "startshere");
  Log.w("urloutput", total.toString());

  return total.toString();
 }