I'm trying to implement the HttpDelete, I've used HttpGet and HttpPost, and worked well.
First think, I saw that on HttpDelete, I can not put del.setEntity(entity); where entity is StringEntity entity = new StringEntity(usuari.toString()); and usuari is the JSON.
Since I can't put entity on my HttpDelete, I tried this:
boolean resul = true;
HttpClient httpClient = new DefaultHttpClient();
HttpDelete del = new HttpDelete(getResources().getString(R.string.IPAPI) + "produsuaris/produsuari");
del.setHeader("content-type", "application/json");
try {
JSONObject usuari = new JSONObject();
try {
usuari.put("idProducte", params[0]);
usuari.put("idusuari", params[1]);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpResponse resp = httpClient.execute(del);
String respStr = EntityUtils.toString(resp.getEntity());
if (!respStr.equals("true")) ;
resul = false;
} catch (Exception ex) {
Log.e("ServicioRest", "Error!", ex);
}
return resul;
I don't know how to put the JSONObject usuari on the entity of my HttpDelete. What I'm missing or what I'm doing wrong?