在 spring 启动时在 DeleteMethod 中传递 RequestBody

Pass RequestBody in DeleteMethod in spring boot

为了调用第三方API的删除请求,我需要传递一个请求体来发出删除请求。可能吗?

规范 RFC 7231 不阻止在 DELETE 方法中接受 RequestBody。

A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing  implementations to reject the request.

如果底层 Web 服务器配置为解析正文以进行 DELETE 方法,则您可以接受请求正文。

所以我找到了我正在寻找的方式。可以使用 Rest 模板解决问题

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