Spring RestTemplate 最适合发送一些数据并且不需要的方法 return
Spring RestTemplate most suitable method for sending some data and expecting no return
Spring 提供了三种向服务器发送数据的方式,POST、PUT 和交换。
我有一个要求,我只是向服务器发送一个 ID 和一个 SecretKey 以通知一些操作,我我期待服务器没有 return。
为了发送此数据,我使用 MultiValueMap
目前我正在使用 postForObject
,ResponseType
为 null,但在运行时它给我错误提示 ResponseType
不能为 null。那么,处理此类情况的最佳方法是什么
您可以将 ResponseEntity
与 Void
一起使用
ResponseEntity<Void> result = template.get().exchange(
<Url>, HttpMethod.PUT, null,
Void.class);
Spring 提供了三种向服务器发送数据的方式,POST、PUT 和交换。
我有一个要求,我只是向服务器发送一个 ID 和一个 SecretKey 以通知一些操作,我我期待服务器没有 return。
为了发送此数据,我使用 MultiValueMap
目前我正在使用 postForObject
,ResponseType
为 null,但在运行时它给我错误提示 ResponseType
不能为 null。那么,处理此类情况的最佳方法是什么
您可以将 ResponseEntity
与 Void
ResponseEntity<Void> result = template.get().exchange(
<Url>, HttpMethod.PUT, null,
Void.class);