Required request body content is missing: org.springframework.web.method.HandlerMethod$HandlerMethodParameter
Sorry guys.. actually because of a csrf token was needed I was getting that issue.
I have implemented spring security and csrf is enable. And through ajax call I need to pass the csrf token.
org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing:
Try to send the auditCycleList as a RequestBody param, as the controller is expecting :
You could build the request like this:
var req = {
method: 'POST',
url: 'PlanAuditController/saveUpdateAnualAudit',
headers: {
'Content-Type': "application/json"
},
data: $scope.auditCycleLst
}
$http(req).success(function(){...}).error(function(){...});
Sending Request body for GET method in AXIOS throws error
As per my understanding, http allows to have a request body for GET method.
While this is technically true (although it may be more accurate to say that it just doesn't explicitly disallow it), it's a very odd thing to do, and most systems do not expect GET requests to have bodies.
Consequently, plenty of libraries will not handle this.
The documentation for Axois says:
// `data` is the data to be sent as the request body
// Only applicable for request methods 'PUT', 'POST', and 'PATCH'
Under the hood, if you run Axios client side in a web browser, it will use XMLHttpRequest. If you look at the specification for that it says:
client . send([body = null])
Initiates the request. The body argument provides the request body, if any, and is ignored if the request method is GET or HEAD.
Bug: Required request body is missing
Issue is in this code.
@RequestBody String id, @RequestBody String oldPass,
@RequestBody String newPass
You cannot have multiple
@RequestBody
in same method,as it can bind to a
single object only (the body can be consumed only once).
APPROACH 1:
Remedy to that issue create one object that will capture all the relevant data, and than create the objects you have in the arguments.
One way for you is to have them all embedded in a single JSON as below
{id:"123", oldPass:"abc", newPass:"xyz"}
And have your controller as single parameter as below
public Message changePassword(@RequestBody String jsonStr){
JSONObject jObject = new JSONObject(jsonStr);
.......
}
APPROACH 2:
Create a custom implementation of your own for ArgumentResolver
Related Topics
How to Override Spring Data JPA Repository Base Methods
Mailconnectexception: Couldn't Connect to Host, Port: Smtp.Sendgrid.Net
How to Wait for All Threads to Finish, Using Executorservice
Safely Generate Random Numbers Between Some Range in Java
How to Increment a Variable to the Next or Previous Letter in the Alphabet
How to Write New Line Character to a File in Java
Most Efficient Solution for Reading Clob to String, and String to Clob in Java
Get Enum Values as List of String in Java 8
This Program Is About String Compression in Java
How to Specify the Path for Getresourceasstream() Method in Java
How to Shut Down a Spring Boot Command-Line Application
Statefulbeantocsv With Column Headers
Parsing the Nested Json Array Using Jackson Library in Java
Cannot Get Jedis Connection; Could Not Get a Resource from the Pool
Password Encrypt and Decrypt Using Spring-Security
How to Execute SQL Script File in Java
A Better Way to Convert Integer (May Be Null) to Int in Java