How Can I Perform A Http Delete Request With Body?
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 limitatio
Solution 1:
This code will make it:
try {
HttpEntityentity=newStringEntity(jsonArray.toString());
HttpClienthttpClient=newDefaultHttpClient();
HttpDeleteWithBodyhttpDeleteWithBody=newHttpDeleteWithBody("http://10.17.1.72:8080/contacts");
httpDeleteWithBody.setEntity(entity);
HttpResponseresponse= 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
Solution 2:
why not do this with HttpClient
classMyDeleteextendsHttpPost{
publicMyDelete(String url){
super(url);
}
@OverridepublicStringgetMethod() {
return"DELETE";
}
}
it works well.
Post a Comment for "How Can I Perform A Http Delete Request With Body?"