How to send POST-request with request arguments using cURL?
Analysis
Long story short, conceptually, @RequestParam
and @RequestBody
are mutually exclusive: query parameters (@RequestParam
) are sent as a request body.
Please see the additional details here:
- How are parameters sent in an HTTP POST request?.
- Spring MVC - Why not able to use @RequestBody and @RequestParam together.
- spring - Invoking service with @RequestParam and @RequestBody using postman client.
- spring - What is difference between @RequestBody and @RequestParam?.
Solution
Currently, there are two alternatives:
- Stick to the request parameters (
@RequestParam
) only: pass every parameter (i.e. every JSON property) as a query parameter. Stick to the request body (
@RequestBody
) only, for example:- Pass everything as a JSON request body.
- Pass everything as a JSON request body, except the
user_id
parameter. The parameter may be made@PathVariable
and the@RequestMapping
should use the appropriate placeholder to reference it.