【问题标题】:Data not being sent Axio post request from React Native to Spring Boot API数据未从 React Native 发送到 Spring Boot API 的 Axio 发布请求
【发布时间】:2020-11-03 14:36:24
【问题描述】:

当我尝试从 React 本机向我的 Spring Boot API 发出 axio post 请求时,我的数据没有被发送?

这是我在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))
  )

}

【问题讨论】:

  • 当我在 Spring Boot 应用程序中看到错误日志时,如下所示: Loading User Details for User: NONE_PROVIDED \\ 我认为这意味着它没有收到任何数据

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


【解决方案1】:

也许,您不使用 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));

【讨论】:

  • 它给了我以下错误:可能未处理的承诺拒绝(id:0):ReferenceError:找不到变量:错误
  • 对不起,我忘记了我的一些代码块。请再试一次。我修好了。
猜你喜欢
  • 2016-11-27
  • 2020-07-05
  • 2017-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-09
  • 2019-06-25
  • 1970-01-01
相关资源
最近更新 更多