Beispiel #1
0
 public static String delete(String url, String data) {
   /* DELETE Method */
   final HttpDeleteWithBody delete = new HttpDeleteWithBody(url);
   try {
     delete.setEntity(new StringEntity(data));
     return EntityUtils.toString(client.execute(delete).getEntity());
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
  public static String DELETE(String url, allTransactionsM model) {
    InputStream inputStream = null;
    String result = "";
    try {

      HttpClient httpclient = new DefaultHttpClient();

      HttpDeleteWithBody delete = new HttpDeleteWithBody(url);

      String json = "";

      JSONObject jsonObject = new JSONObject();
      jsonObject.accumulate("id", model.getId());
      jsonObject.accumulate("productGroup", model.getProductGroup());
      jsonObject.accumulate("productName", model.getProductName());
      jsonObject.accumulate("transaction", model.getTransaction());
      jsonObject.accumulate("date", model.getDate());

      json = jsonObject.toString();

      StringEntity se = new StringEntity(json);

      delete.setEntity(se);

      delete.setHeader("Accept", "application/json");
      delete.setHeader("Content-type", "application/json");

      HttpResponse httpResponse = httpclient.execute(delete);

      inputStream = httpResponse.getEntity().getContent();

      if (inputStream != null) result = convertInputStreamToString(inputStream);
      else result = "Did not work!";

    } catch (Exception e) {
      Log.w("InputStream", e.toString());
    }
    return result;
  }