0

I have server running on Spring and it has a rest method for GET, here is what it looks like:

@GetMapping("/user")
    ParentInOut getUsersOnly(@RequestBody ParentInOut clientSide)
    {
        return new ParentInOut(userRepository.findAll());
    }

I'm trying to use axios in my react.js application to get data:

let dumbJSON={
        "messages":"",
        "localDateTime":getValue(parameter)
    };
    const config = {
        method: 'GET',
        url: url,
        body : dumbJSON,
        headers: {
            'Content-Type': 'application/json'
        }
    };
    axios(config).then(function (res) {
        console.log(res);
    }).catch(function (err) {
        console.log(err);
    });

But it gives me error,saying Error: Request failed with status code 400 in web-console

And in spring console, I get Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: warning

How this can be resolved ?

I have also tried this :

var headers = {
        'Content-Type': 'application/json'
    };
    axios
        .get(url, dumbJSON, {headers})
        .then(response => {
            console.log(response);
        })
        .catch(erro => {
            console.log(erro.response);
        });

Gives me same error and warning but this time gets a response, which is the axios object itself with dumbJSON,headers,url etc.

Maifee Ul Asad
  • 3,992
  • 6
  • 38
  • 86
  • 1
    Can you be more specific? You have Post mapping in java code and are using get mapping in your request from react code? – Sudip Bolakhe Dec 13 '19 at 05:39
  • @SudipBolakhe, that was a mistake, i corrected it – Maifee Ul Asad Dec 13 '19 at 05:41
  • Please use post mapping for sending a request body. Or pass the value as the request parameter. Refer to this post and answer https://stackoverflow.com/questions/42256358/spring-getmapping-with-requestparam-and-requestbody-fails-with-httpmessagenot – Sudip Bolakhe Dec 13 '19 at 05:55

0 Answers0