I am trying to send DELETE request with body. So, I decided to use CURL to complite this task.
curl -X DELETE "URL" -H "Authorization: Token XXX" -H "Content-Type: application/json" -d "ENTITY"
When I send above command from terminal, I am able to receive below output
{
"data": null,
"status_code": "1000",
"status_message": "Success",
"timestamp": "2023-03-23T13:43:20.910098300Z"
}
When I try to do same process with Spring boot app, It always fails. It returns empty string to test
variable. When I debug, I can see that inputStream
, process
or processBuilder
are not null
String command = "curl -X DELETE ........ ";
ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
String test = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
statusMessage = new JSONObject(test).get("status_message").toString();
I have checked followings and I couldn't handle the problem;
- How to run a curl command from java?
- Java executing curl command not working on some commands
- How to use cURL in Java?
- cURL DELETE on java
BTW, I am not obligated to use cURL
, if you have any other solutions, please let me know.