Sample code for 30+ languages & platforms
Java

HTTP DELETE with Body

See more HTTP Examples

Demonstrates how to send a DELETE request with a body.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();

    // Use the HttpStr method (or HttpSb) to send a DELETE request with a body.
    String requestBody = "{ \"abc\": 123 }";
    CkHttpResponse resp = new CkHttpResponse();
    success = http.HttpStr("DELETE","https://example.com/something",requestBody,"utf-8","application/json",resp);
    if (success == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    System.out.println("Response status: " + resp.get_StatusCode());
    System.out.println("Response body: ");
    System.out.println(resp.bodyStr());
  }
}