title: Network request failed Android
body: <p>While working on a Weather app written in react native, I am getting the 'Network request failed' error on Android while the app is working fine on iOS.</p>
  
  <p><a href="https://i.stack.imgur.com/DEtp3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DEtp3.png" alt="enter image description here"></a></p>
  
  <p>Here is the fetch function - </p>
  
  <pre><code>componentDidMount: function() {
      navigator.geolocation.getCurrentPosition(
      location =&gt; {
        // this variable will contain the full url with the new lat and lon
        var formattedURL = REQUEST_URL + "lat=" + location.coords.latitude + "&amp;lon=" + location.coords.longitude+"&amp;APPID=e5335c30e733fc682907a126dab045fa";
  
        // this will output the final URL to the Xcode output window
        console.log(location.coords.latitude);
        console.log(location.coords.longitude);
        console.log(formattedURL);
  
        // get the data from the API
        this.fetchData(formattedURL);
  
        },
      error =&gt; {
        console.log(error);
      });
    },
  
    // fetchdata takes the formattedURL, gets the json data and
    // sets the apps backgroundColor based on the temperature of
    // the location
    fetchData: function(url) {
      fetch(url)
        .then((response) =&gt; response.json())
        .then((responseData) =&gt; {
  
          // set the background colour of the app based on temperature
          var bg;
          var temp = parseInt(responseData.main.temp);
          if(temp &lt; 14) {
            bg = BG_COLD;
          } else if(temp &gt;= 14 &amp;&amp; temp &lt; 25) {
            bg = BG_WARM;
          } else if(temp &gt;= 25) {
            bg = BG_HOT;
          }
  
          // update the state with weatherData and a set backgroundColor
          this.setState({
            weatherData: responseData,
            backgroundColor: bg
          });
        })
        .done();
    },
  </code></pre>
  
  <p>I have also referred to other questions here on stackoverflow but they all revolve around changing localhost to your local ip address like 127.0.0.1. In my case I have no where used localhost.</p>