未将数据从React Native发送到Spring Boot API的Axio发布请求

时间:2020-07-14 09:32:57

标签: mysql spring-boot react-native post axios

当我尝试从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))
  )

}

1 个答案:

答案 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));