0

I have a requirement where I need to send a JSON data to HTTPDelete. There is no setEntity() for Delete.

HttpClient httpClient = new DefaultHttpClient();
HttpDelete httpDel = new HttpDelete(DEL_URL);
StringEntity se = new StringEntity(jsonobj.toString());

//Couldnt set entity.
httpDelReq.setEntity(se);

Is there any possible way to send the JSON data to server

Vamsee
  • 1
  • 2

1 Answers1

0

this link can help you: HttpDelete with body

That will create a HttpDelete-lookalike that has a setEntity method. I think the abstract class does almost everything for you, so that may be all that's needed.

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import java.net.URI;
import org.apache.http.annotation.NotThreadSafe;

@NotThreadSafe
class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
  public static final String METHOD_NAME = "DELETE";
  public String getMethod() { return METHOD_NAME; }

  public HttpDeleteWithBody(final String uri) {
    super();
    setURI(URI.create(uri));
  }
  public HttpDeleteWithBody(final URI uri) {
    super();
    setURI(uri);
  }
  public HttpDeleteWithBody() { super(); }
}
Community
  • 1
  • 1
Fred
  • 3,365
  • 4
  • 36
  • 57