Required Request Body Content Is Missing: Org.Springframework.Web.Method.Handlermethod$Handlermethodparameter

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



Leave a reply



Submit