Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot POST request with missing request body?

I have a very simple HTML form page (which is a part of Spring Boot web application in src/main/resources/public/web.html) to post a String from a textarea to a Spring Boot web application version 1.5.2.

<form action="" method="post">
<textarea cols="128" rows="40" name="query"></textarea>
<input value="Send" type="submit">
</form>

And the SpringBoot class to handle the POST request:

@RestController
public class QueryController {
    @RequestMapping(value = "/handle", method = RequestMethod.POST)
    protected void handlePost(@RequestBody String postBody) throws Exception {
       // Get query from postBody here
    }
}

It works with small String from textarea in client. However, when the String is big (e.g: with HTTP request header: Content-Length:3789333 (3 MB)). Spring Boot throws an exception like this:

org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: protected void QueryController.handlePost(java.lang.String) throws java.lang.Exception
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:154)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:128)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)

I'm not sure what causes this problem, I'm running the web application with embedded Tomcat from Spring Boot.

like image 827
Bằng Rikimaru Avatar asked Oct 28 '22 19:10

Bằng Rikimaru


1 Answers

I'm not sure but could this be caused by missing the encoding of the content?

like image 171
P. Edge Avatar answered Nov 15 '22 06:11

P. Edge