Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 我有时会遇到意想不到的结局 描述问题_React Native_Axios - Fatal编程技术网

React native 我有时会遇到意想不到的结局 描述问题

React native 我有时会遇到意想不到的结局 描述问题,react-native,axios,React Native,Axios,我用的是react native。我的回答是正确的,但有时我会回答:“意外的结局”。当我尝试邮递员时,我不会犯任何错误 示例代码 api服务 async function postv2(url, data = {}) { const params = new URLSearchParams(); for (var property in data) { let encodedKey = encodeURIComponent(property); let encodedVa

我用的是react native。我的回答是正确的,但有时我会回答:“意外的结局”。当我尝试邮递员时,我不会犯任何错误

示例代码 api服务

async function postv2(url, data = {}) {
  const params = new URLSearchParams();
  for (var property in data) {
    let encodedKey = encodeURIComponent(property);
    let encodedValue = encodeURIComponent(data[property]);
    params.append(encodedKey, encodedValue);
  }
  return await axios({
    method: 'post',
    timeout: 10000,
    url: URL+url,
    data: params,
    headers:{
      'Content-Type': 'application/json',
      'Access-Control-Allow-Origin':'*'
    }
  })
 .catch(function (error) {
  if (error.response) {
    // Request made and server responded
    console.log(error.response.data);
    console.log(error.response.status);
    console.log(error.response.headers);
  } else if (error.request) {
    // The request was made but no response was received
    console.log(error.request);
  } else {
    // Something happened in setting up the request that triggered an Error
    console.log('Error', error.message);
  }
    });
}
使用功能

async function fetchList() {
    await ApiService.postv2('/see_and_sign/v1.0/get_global_campaigns', {}).then(
      (response) => {
        console.log(response);
        setList(response.data);
      },
    );
  }
环境
  • Axios版本[0.21.0]
  • 反应天然[0.63.3]