Rest API : Post API Throwing 400 Bad request


Use Case –

I am having a post API which is supposed to consume Content-Type = x-www-form-urlencoded.
When creating individual boot project and implementing POST API, I am getting Form Data in my controller(testing it using postman), but when the same code I integrate it in my project which is Spring MVC project, whenever I test it always gives me 400 Bad request in Response.

  @RequestMapping(value = "/registration", method = RequestMethod.POST,consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public void marketplaceRegistration(@RequestBody MultiValueMap<String, String> formData, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException {"\nIn registration method: TOKEN RECIEVED IS "+formData.getFirst("token"));}

this is my method where I will be receiving request. I have used @RequestBody , @RequestParam Both annotation and both works fine with the spring boot applciation but when I am integrating this is throwing 400 Bad request.

The only difference is we are having a WsFilter from apache in place.
Not sure what is wrong but if anyone can help that would be great.


So Apparently, In My Project where I was integrating the Post API with ContentType is x-www-form-urlencoded, a filter was reading the request and due to which the request body of urlencoded form data was getting lost.
Upon removing the filter, my request are going through controller and I am able to get the 200 response.

Unfortunately can’t post the filter logic here.

Answered By – agaonsindhe

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published