react native 请求注意事项

请求地址一定得为域名形式,不能是ip####

错误请求:axios.get('127.0.0.1:3000/test').then(res=>{}).catch(err=>{})//会进入catch里面
正确请求:axios.get('http://asd.tunnel.qydev.com/test').then(res=>{}).catch(err=>{})//请求成功

axios.get请求####

axios.get('http://asd.tunnel.qydev.com/test',{
      params:{
        username: 'xxx',
        pass: 'xxx'
      }
    })
      .then(res => {
        console.log('res:', res)
      })
      .catch(err => {
        console.log('err:', err)
      })

axios.post请求####

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

async await写法####

async getData(){
      // let data = await axios.get('http://asd.tunnel.qydev.com/test')
      let data = await axios.post('http://asd.tunnel.qydev.com/login',{name:'123',pass:'123'})
      console.log('data:', data)
}