Java HTTP DELETE with Request Body

前端 未结 4 1825
难免孤独
难免孤独 2021-01-20 00:44

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

4条回答
  •  感动是毒
    2021-01-20 01:25

    If you are using Spring, you can use RestTemplate to generate the client request. In this case you could use RestTemplate.exchange and provide the url, http method and request body. Something like (not tested, but you get the idea):

    RestTemplate restTemplate = new RestTemplate();
    HttpEntity request = new HttpEntity<>(new Foo("bar"));
    restTemplate.exchange(url, HttpMethod.DELETE, request, null);
    

提交回复
热议问题