我試圖執行HttpDelete
,我用HttpGet
和HttpPost
,並且運行良好。Android - 帶JSON的HttpDelete
首先想到的,我看到的HttpDelete
,我不能把del.setEntity(entity);
其中實體StringEntity entity = new StringEntity(usuari.toString());
和usuari
是JSON
。
因爲我不能把實體對我HttpDelete
,我嘗試這樣做:
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;
我不知道如何把JSONObject usuari
我HttpDelete
的實體。我錯過了什麼或者我做錯了什麼?
我不想健全由你爲什麼不嘗試改變一個更完整的HTTP客戶端煩人?有了[Ion](https://github.com/koush/ion),你可以在5,6行代碼中做這種事情。 – 4gus71n
我已經得到所有的POST和GET這個方法...我不想改變我的代碼,我認爲與HttpDelete這是可能的 –
可能重複[HttpDelete與正文](http://stackoverflow.com/ question/3773338/httpdelete-with-body) – 4gus71n