reactjs - HttpMessageNotReadableException:缺少所需的请求正文
问题描述
我有在 Spring 上运行的服务器,它有一个 rest 方法GET
,它看起来像这样:
@GetMapping("/user")
ParentInOut getUsersOnly(@RequestBody ParentInOut clientSide)
{
return new ParentInOut(userRepository.findAll());
}
我正在尝试axios
在我的 react.js 应用程序中使用来获取数据:
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 控制台中,我得到了Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: warning
如何解决?
我也试过这个:
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对象本身。
解决方案
推荐阅读
- aem - 我如何反映从 AEM 作者服务器到发布服务器的更改?
- c# - 如何在unity3d中平滑地向上或向下移动刚体对象
- python-3.x - 使用 QFiledialog 保存或打开文件而不覆盖数据
- swagger - 招摇文档不反映对象价值
- python - RuntimeError:未指定表格列/单元格宽度,无法继续
- firebase - 重定向登录后getRedirectResult返回null
- gradle - 如何在 settings.gradle 中包含另一个根项目
- laravel - 如何在控制器中使用hasone关系显示两个表的组合数据
- css - 添加中间页脚会删除页面标题
- reactjs - react16 的日期选择器库