Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 30010

React Native Fetch API only works in develop enviroment

$
0
0

Im using fetch API to retrieve data from my node server to react native application. It works well when I execute the app in Android Studio emulator or a phsycal device, but when I build it to export external APK, app cannot perform request. Type Error: Network request failed Error img This is the fetch in React Native

NetInfo.fetch().then(state => {
  if (state.isConnected) {
    fetch('http://example/API2/clients', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        nombre: this.state[key],
      }),
    })
    .then(response => response.json())
    .then(responseJson => {
      console.log(responseJson);
    })
    .catch(error => {
      console.log(error);
      Alert.alert(
        'Lo sentimos',
        'No se ha recibido respuesta del servidor' + error,
      );
    });
  } else {
    Alert.alert('Sin conexión a internet', 'Verifique su conexión');
  }
});

I noticed request are not even getting out from client. React-native version: 0.61


Viewing all articles
Browse latest Browse all 30010

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>