HttpMessageNotReadableException:缺少必需的请求正文

时间:2019-12-13 05:34:44

标签: reactjs spring spring-boot get axios

我的服务器在Spring上运行,它具有GET的rest方法,如下所示:

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

我正在尝试在我的react.js应用程序中使用axios来获取数据:

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);
    });

但是它给了我错误,说错误:网络控制台中的请求失败,状态码为400

在Spring控制台中,我得到已解决的[org.springframework.http.converter.HttpMessageNotReadableException:缺少所需的请求正文:警告

如何解决?

我也尝试过这个:

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

给我相同的错误和警告,但是这次得到响应,这是带有dumbJSON,headers,url等的axios对象本身。

0 个答案:

没有答案