4

I need to send an ID to the server and have the server to delete one record in a DB. I want to use the HttpDelete Apache Android SDK integrated class but I cannot figure out how to use it and how to pass parameters to the server. With the POST request I use .setEntity method on the HttpPost class. But in HttpDelete there's no .setEntity method.

What I have so far achieved is:

 HttpClient httpclient = new DefaultHttpClient();
 HttpDelete httpdelete = new HttpDelete(url);
 httpdelete.setHeader(HTTP.CONTENT_TYPE, "text/xml");
 response = httpclient.execute(httpdelete);

1 Answer 1

7

HTTP DELETE requests do not have a body. You pass parameters right on the URL:

 String url = "http://foo.com/bar?bing=bang"
 HttpDelete httpdelete = new HttpDelete(url);
Sign up to request clarification or add additional context in comments.

2 Comments

So should I treat it like a GET method ?
Yes, treat it like a GET method in that you are putting your data on the URL. However presumably you have chosen the DELETE verb over GET for a good reason. If this is a REST service, DELETE is used to delete a resource from the server. GET is used to read the resource.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.