Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring post method "Required request body is missing"

@PostMapping(path="/login")
public ResponseEntity<User> loginUser(@RequestBody Map<String, String> userData) throws Exception {
    return ResponseEntity.ok(userService.login(userData));
}

I have this method for the login in the UserController. The problem is when i try to make the post request for the login i get this error:

{
"timestamp": "2018-10-24T16:47:04.691+0000",
"status": 400,
"error": "Bad Request",
"message": "Required request body is missing: public org.springframework.http.ResponseEntity<org.scd.model.User> org.scd.controller.UserController.loginUser(java.util.Map<java.lang.String, java.lang.String>) throws java.lang.Exception",
"path": "/users/login"
}

enter image description here

like image 277
Ionut Avatar asked Oct 24 '18 16:10

Ionut


2 Answers

I had a similar issue, was getting this error in my Spring Boot service

HttpMessageNotReadableException: Required request body is missing:...

My issue was that, when I was making requests from Postman, the "Content-Length" header was unchecked, so service was not considering the request body.

like image 135
Florin D Avatar answered Sep 19 '22 02:09

Florin D


You have to pass that as JSON in your body, if it's a POST request.

enter image description here

like image 34
cosmos Avatar answered Sep 20 '22 02:09

cosmos