0

I'm using Spring MVC with Spring boot for implements REST in our project. And we are using Embedded Tomcat as our web-server.I encountered an issue recently.

This is how my POST service handler looks like

@RequestMapping(value = "/v2", method = RequestMethod.POST,consumes ={"application/json", "text/plain","application/x-www-form-urlencoded" })
public void handleV2(@RequestBody String json){
    log.info("Post body received : "+json);
}

When client sends % character in post body with content-type:application/x-www-form-urlencoded, json is received as empty.

There are no issues if the client sends % in post body with content-type:application/json . I couldn't figure out what the issue is.

First I thought this could be a client side issue. But my colleague who implemented the same handler in python has no issues with this.

Thanks in advance for the help.

Ganesh P
  • 1,075
  • 1
  • 13
  • 19
  • 1
    Your piece of code has a syntax fault, please fix it. Apart from that, is it happening only when the `%` symbol appears anywhere in the body? I understand `content-type:application/x-www-form-urlencoded` shouldn't be used with @RequestBody, as it is explained [here](http://stackoverflow.com/questions/4339207/http-post-with-request-content-type-form-not-working-in-spring-mvc-3). – Aritz Mar 19 '16 at 17:08
  • @Xtreme Biker, Thanks for pointing syntax error. I corrected it. I have gone through your referenece link. Here the data type is String. Do I still need to use that **_ModelAttribute_** annotaion ? – Ganesh P Mar 19 '16 at 17:20
  • 1
    I haven't tried it, but I have my doubts for String being able to parse a request body to an object when the header comes as `"application/x-www-form-urlencoded"`. You could try mapping [the whole request](http://stackoverflow.com/questions/7312436/spring-mvc-how-to-get-all-request-params-in-a-map-in-spring-controller) for your method parameters and trying to clarify if the body is being received properly. Stil, I strongly believe that a `@RequestBody` has to be a structured piece of information such a JSON,XML or a file, but not a random form. – Aritz Mar 19 '16 at 17:27

0 Answers0