1

I have a source which calls a post api and the request is url encoded. How can I retrieve the request data that is url encoded using spring boot.

Update

In my controller I have below method,

@PostMapping(value = "/res", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public Map<String, Object> postResponse(@RequestBody Map<String, Object> url) {...}

It returns error

"error": "Unsupported Media Type", "message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"

How can I get form-urlencoded data in controller

user8765332
  • 85
  • 3
  • 9
  • Use URLDecoder.decode(value, StandardCharsets.UTF_8.toString()); or use Base64 encoder and decoder Link: https://stackoverflow.com/a/19743925/540195 – Amit May 15 '18 at 11:18
  • 1
    At least show us what you have done so far or even take time to write a snippet demonstrating your problem. – tmarwen May 15 '18 at 11:21

1 Answers1

2

I got the answer finally.

url encoded values can be read as String

@PostMapping(value = "/res", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public Map<String, Object> postResponse(@RequestBody String request) {...}
user8765332
  • 85
  • 3
  • 9