10

I am trying to use DELETE method of HttpMethod. The code that I am using for that is

response = restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, Response.class); 

I am also using JacksonJson for mapping json. The delete functionality returns the json which should be mapped to Response class. But calling the above line doesn't works and gives internal server error with 500 as response code. But, the same API does work with RESTClient in the browser so I guess there is something that I am not doing correctly.

2 Answers 2

9

After doing some more research it seems that DELETE method doesn't supports request body. As we had the control over REST API we have changed the request body to be added as parameters. After doing this change the request is working properly.

Hope it helps someone.

Sign up to request clarification or add additional context in comments.

3 Comments

I found solution at this link working well for passing request body in DELETE method request
Ujjwal, thank you, helped a lot - it's a final solution
Why do u want to send delete request with body . It should have Path Parameter and Query parameter Only
0

A little late to the party I'd like to chime in here as well (document my solution for posterity)

I'm too using spring's rest template, also trying to perform a delete request with a payload AND i'd also like to be able to get the response code from the server side

Disclaimer: I'm on Java 7

My solution is also based on a post here on SO, basically you initially declare a POST request and add a http header to override the request method:

RestTemplate tpl = new RestTemplate(); /* * http://bugs.java.com/view_bug.do?bug_id=7157360 * As long as we are using java 7 we cannot expect output for delete * */ HttpHeaders headers = new HttpHeaders(); headers.add("X-HTTP-Method-Override", "DELETE"); HttpEntity<Collection<String>> request = new HttpEntity<Collection<String>>(payload, headers); ResponseEntity<String> exchange = tpl.exchange(uri, HttpMethod.POST, request, String.class); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.