我有一个服务器和一个客户端。我正在使用 Spring 在服务器上映射 http 请求,并使用 RestTemplate 向服务器发出请求。
服务器代码如下所示:
@RequestMapping (value="/someEndPoint", method = RequestMethod.POST)
@ResponseBody
public String configureSettings(
@RequestParam(required=false) Integer param1,
@RequestParam(required=false) Long param2,
@RequestBody String body)
{
if(param1 != null)
// do something
if(body not empty or null)
//do something
}
客户端:
String postUrl = "http://myhost:8080/someEndPoint?param1=val1"
restTemplate.postForLocation(postUrl, null);
这样做的原因是从 param1 在服务器端触发了正确的操作,但是,请求的主体还包含:
param1=val1
设置的请求主体将是 json,所以我想要的只是能够设置其他参数没有设置身体。我知道我使用 restTemplate 不正确,所以任何帮助将不胜感激。