I have an external API which uses DELETE with the body(JSON). I make use of Postman REST Client and get the delete done with request body and it works fine. I am trying to a
This code worked for me:-
Write the json body into OutputStreamWriter, in my sample, i converted Java object to json using Jackson ObjectMapper
URL url = new URL("http://localhost:8080/greeting");
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestProperty(
"Content-Type", "application/json");
httpCon.setRequestMethod("DELETE");
OutputStreamWriter out = new OutputStreamWriter(
httpCon.getOutputStream());
ObjectMapper objectMapper = new ObjectMapper();
out.write(objectMapper.writeValueAsString(new Greeting("foo")));
out.close();
httpCon.connect();