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

2
  • Use URLDecoder.decode(value, StandardCharsets.UTF_8.toString()); or use Base64 encoder and decoder Link: stackoverflow.com/a/19743925/540195 Commented May 15, 2018 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. Commented May 15, 2018 at 11:21

1 Answer 1

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) {...} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.