setEntity in HttpDelete

I do not believe that HTTP DELETE takes input - I believe it acts like a GET variant.

The implementation provided by HTTP Client seems to support this conjecture as well.

If you are looking to provide a delete with a body, you /might/ want to consider using a POST to a location that accepts a body.

But in answer to your question, no, delete does not accept a body. You can add query parameters but not a body.


class MyDelete extends HttpPost
{
    public MyDelete(String url){
        super(url);
    }
    @Override
    public String getMethod() {
        return "DELETE";
    }
}

Make your class extend the http delete class over there and during making the object of your class sent entity and you will be able to post the data in httpdelete

HttpResponse httpResponse;
String result = null;
HttpClient httpClient = new DefaultHttpClient();

HttpConnectionParams
        .setConnectionTimeout(httpClient.getParams(), 10000);


MyDelete httpDelete = new MyDelete(urlUnfollowPatientBundle);
StringEntity entity = null;
try {
    entity = new StringEntity(rawData);
    httpDelete.setEntity(entity);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
}

try {

    httpResponse = httpClient.execute(httpDelete);
    if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        HttpEntity httpEntity = httpResponse.getEntity();
        result = EntityUtils.toString(httpEntity);
        status = true;
    }

HTTPDelete will not carry any payload.

HttpDelete will just take the uri/url to be delete and issues a DELETE HTTP Header to the said resource.

Tags:

Java

Android