Post body empty when using Spring MVC @RequestParam to handle a application/x-www-form-urlencoded form POST
See original GitHub issueWhen logbook-spring-boot-starter
is enabled @RequestParam
are null
Description
For a valid form POST the following code results in a 400 error. The Spring controller doesn’t see the POST body and the fields are null. Since the @RequestParam
fields are required it returns a 400 error.
@PostMapping("/form")
public ModelAndView handlePost(@RequestParam String field1, @RequestParam String field2) {
Expected Behavior
The POST body should be processed by Spring MVC whether or not logbook is enabled.
Actual Behavior
Spring MVC can’t process the POST.
Possible Fix
Saw a similar bug about missing a flush call. We use logbook on another project that has a JSON POST body and it works fine. Seems to just be isolated to application/x-www-form-urlencoded
Steps to Reproduce
See https://github.com/dillon-sellars/logbook-bug
Context
Just wanted to add logging to app, broke form posts instead.
Your Environment
- Version used: 2.3.0
- Link to your project: https://github.com/dillon-sellars/logbook-bug
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
How to properly receive urlencoded form body with Spring
It just gets set to null. I send it from Postman, as a post request, with the content type set, and my parameters...
Read more >Springboot : @RequestParam in controller reads the request ...
Coding example for the question Springboot : @RequestParam in controller reads the request with '&' and '#' as empty-Spring MVC.
Read more >Handling URL Encoded Form Data in Spring REST - Baeldung
Learn how to handle URL encoded form data in Spring REST. ... But, if we're using the POST method, then its data is...
Read more >How to handle URL Encoded Form Data in Spring REST?
Sometimes, our REST endpoint needs to consume data in the form of application/x-www-form-urlencoded or using multipart/form-data. The source of ...
Read more >Writing REST Services with RESTEasy Reactive - Quarkus
POST /cheeses;variant=goat/tomme?age=matured HTTP/1.1 Content-Type: application/x-www-form-urlencoded Cookie: level=hardcore ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah I see, but your default configuration should not break the way servlets work. I would consider making the default
parameter
oroff
. I would go so far as to say the body options shouldn’t even exist - does an option where getParameter doesn’t work have a valid use?This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don’t have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.