当我尝试从React Native向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))
)
}
答案 0 :(得分:0)
也许,您不使用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));