发送HTTP DELETE中的Andr​​oid请求

问题描述:

我的客户的API指定删除对象,DELETE请求必须发送包含描述内容的Json头数据。有效是相同的呼叫如添加一个对象,这是通过POST完成。这工作得很好,我的code胆量是如下:

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();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setUseCaches(false);
con.connect();
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(data); // data is the post data to send
wr.flush();

要发送删除请求,我改变了请求方法为删除相应。不过,我得到以下错误:

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

java.net.ProtocolException: DELETE does not support writing

所以,我的问题是,如何从发送包含Android的头数据DELETE请求?我错过了一点 - 你能头数据添加到DELETE请求?谢谢你。

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.

要添加封闭了这个问题,它蒸发了,没有支持的方法来发送包含头数据的HTTP DELETE请求。

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

的解决方案是为客户端,以改变它们的API来接受这表明动作应删除,包含该项目的ID将被删除的标准GET请求。

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.

http://clienturl.net/api/delete/id12345