私はサーバーとクライアントを持っています。私は、サーバにHTTPリクエストをマップするためにSpringを使用しており、サーバにリクエストを行うためにRestTemplateを使用しています。RestTemplate POSTリクエストRequestParamsとRequestBody
Serverのコードは次のようになります。
@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になりますので、必要なのはtを設定せずに他のパラメータを設定できることです彼の体。 私はrestTemplateを間違って使用しているので、何か助けていただければ幸いです。