不带主体的 Spring RestTemplate POST 方法

sic*_*cio 0 spring resttemplate spring-resttemplate

我正在尝试编写一个客户端,在其中我将执行没有正文的 POST 方法。插入null是唯一的解决方案吗?例子:

client.exchange("/" + userId + "/logout", HttpMethod.POST, null, String.class);
Run Code Online (Sandbox Code Playgroud)

ams*_*ger 5

您也可以通过HttpEntity.EMPTY(或new HttpEntity<>(null)) 那里 - 结果应该是相同的。

如果你有HttpHeaders对象 - 你也可以将它传递到相应的构造函数中:new HttpEntity<>(httpHeaders)