The follwing Spring MVC code throws MissingServletRequestParameterException,
@Controller
@RequestMapping("/users")
public class XXXXResource extends AbstractResource {
.....
@RequestMapping(method = RequestMethod.PUT
, produces = {"application/json", "application/xml"}
, consumes = {"application/x-www-form-urlencoded"}
)
public
@ResponseBody
Representation createXXXX(@NotNull @RequestParam("paramA") String paramA,
@NotNull @RequestParam("paramB") String paramB,
@NotNull @RequestParam("paramC") String paramC,
@NotNull @RequestParam("paramD") String paramD ) throws Exception {
...
}
}
There are no stack traces in the logs, only the Request from Postman returns with HTTP 400 Error.
if you want to
Content-type:application/x-www-form-urlencoded
means that the body of the HTTP request sent to the server should be one giant string -- name/value pairs are separated by the ampersand(&)
and will beurlencoded
as his name implies.name=name1&value=value2
this means that you should not user
@RequestParam
because the arguments are passed in the body of the http request.So if you want to use this
content-type
from their doc:You should use
@RequestBody
withFormHttpMessageConverter
, which will get this giant string and will convert it toMultiValueMap<String,String>
. Here is a sample.