Search code examples
springrestpayload

Match request payload and post method


My back doesn't receive parameters from a mobile app.

org.springframework.web.bind.MissingServletRequestParameterException Required String parameter 'param1' is not present

With Chrome DevTools, I can see that the mobile app call my back with these parameters :

RequestMethod : POST
Request Payload : param1=toto&param2=titi
Request Headers: Content-Type : application/json

I try to retrieve parameters like this :

public void method (@RequestParam(name = "param1") String param1, @RequestParam(name = "param2") String param2) {
...
}

(I tried with "value" instead of "name")

How can I match the payload that the front sends me, with my back ? The payload is imposed on me, it is my back that must be modified

Previously, the back was in Jersey, with @FormParam annotation. I switch the back to spring framework, with the use of RequestParam...


Solution

  • This post resolve my problem to receive a payload in raw with a spring back : How to access plain json body in Spring rest controller? (HttpEntity for me)