Reputation: 5935
I want to perform a HTTP DELETE request with a xml in the body (not a form). How can I perform this HTTP DELETE request?
I tried with HttpURLConnection
but there are some limitations with it.
I tried with the apache's HttpClient
too. But I don't know how to send the xml without the structure of application/x-www-form-urlencoded
.
Upvotes: 1
Views: 7146
Reputation: 7980
This code will make it:
try {
HttpEntity entity = new StringEntity(jsonArray.toString());
HttpClient httpClient = new DefaultHttpClient();
HttpDeleteWithBody httpDeleteWithBody = new HttpDeleteWithBody("http://10.17.1.72:8080/contacts");
httpDeleteWithBody.setEntity(entity);
HttpResponse response = httpClient.execute(httpDeleteWithBody);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
To access the response you can simply do: response.getStatusLine();
And here is the HttpDeleteWithBody class definition: HttpDeleteWithBody
Upvotes: 4
Reputation: 2407
why not do this with HttpClient
class MyDelete extends HttpPost{
public MyDelete(String url){
super(url);
}
@Override
public String getMethod() {
return "DELETE";
}
}
it works well.
Upvotes: 3