androidneil androidneil - 3 months ago 26x
Android Question

Sending HTTP DELETE request in Android

My client's API specifies that to remove an object, a DELETE request must be sent, containing Json header data describing the content. Effectively it's the same call as adding an object, which is done via POST. This works fine, the guts of my code is below:

HttpURLConnection con = (HttpURLConnection)myurl.openConnection();
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(data); // data is the post data to send

To send the delete request, I changed the request method to "DELETE" accordingly. However I get the following error: DELETE does not support writing

So, my question is, how do I send a DELETE request containing header data from Android? Am I missing the point - are you able to add header data to a DELETE request? Thanks.


To add closure to this question, it transpired that there is no supported method to send an HTTP DELETE request containing header data.

The solution was for the client to alter their API to accept a standard GET request which indicated that the action should be a delete, containing the id of the item to be deleted.