2

I know that to send a POST request to the web I can use this syntax:

    HttpPost post = new HttpPost(api_address);
    String response = null;
    int status_code = -1;

    StringEntity se = new StringEntity(json_data, HTTP.UTF_8);
    se.setContentType("application/json");

     // Set entity
      post.setEntity(se);

However, the setEntity methos does not exist for DELETE. So what are the alternatives to send a DELETE with data?

I gave a look to this: HttpDelete with body

but I didnt understand it really... I'm just a beginner!

Community
  • 1
  • 1
Camilla
  • 949
  • 2
  • 14
  • 26

2 Answers2

4

You can use the solution provided in HttpDelete with body like this:

HttpDeleteWithBody delete = new HttpDeleteWithBody(api_address);

StringEntity se = new StringEntity(json_data, HTTP.UTF_8);
se.setContentType("application/json");

delete.setEntity(se);  
Community
  • 1
  • 1
sdabet
  • 18,360
  • 11
  • 89
  • 158
0

This works for me. But the code listed in HttpDelete with body

is using annotation library so removed below portion if you do not wanted to include annotation jars else it is ok.

Import: import org.apache.http.annotation.NotThreadSafe;

Annotation above the class:@NotThreadSafe

and place the class in the application and use it according to "fiddler's" comment.

I am sure you can have result.As i am getting success.

Community
  • 1
  • 1
Ahesanali Suthar
  • 341
  • 3
  • 23