mysql - 数据未从 React Native 发送到 Spring Boot API 的 Axio 发布请求
问题描述
当我尝试从 React 本机向我的 Spring Boot API 发出 axio 发布请求时,我的数据没有被发送?
这是我的apiReq
函数代码:
const apiReq = () => {
return (axios.post('http://{IP address}:8082/api/login', {
headers: {
"Accept": 'application/json',
"Content-Type": "application/json"
},
body: JSON.stringify({
"password": "#####",
"username": "abcd.gmail.com"
})
})
.then(response => {
console.log(response.data.responseMessage.errorCode);
})
.then(result => console.log(result))
.catch(error => console.log('error', error))
)
}
解决方案
也许,您不使用 JSON stringfy。另外,我使用这样的axios。
const body = {
password: "#####",
username: "abcd.gmail.com"
}
const options = {
headers: {
"Accept": 'application/json',
"Content-Type": "application/json"
}
}
axios.post('http://{IP address}:8082/api/login', body, options)
.then(response => console.log(response))
.catch(err => console.log(err));
推荐阅读
- javascript - 如何根据屏幕尺寸播放 2 个不同的视频?
- google-apps-script - Google 循环脚本,如果单元格为 0,则从列表中发送电子邮件
- javascript - React:将抓取的 HTML 内容映射到对象
- javascript - 在一个js文件中调用所有jquery文件
- sql - 查询效率:格式塔不好;零件速度快
- node.js - 这个简单的 node.js 代理为什么以及如何工作?
- python - Python,Tensorflow - 变量没有被初始化
- python - 如何调整子图的高度和宽度以紧密贴合?
- python - 如何使用 Pandas 中列标题中的日期值分配列变量“日期”
- neo4j - 使用 APOC 将 CSV 导入 neo4j 时处理空数组类型