1

I am fetching data via a localhost api using axios in a react native app. If I run it on my web browser, it works fine and the data gets fetched. If I run it on my android emulator then I get a network error.

Here is my code:

componentDidMount() {
    axios.get('http://laravelapi.build/api/art_objects')
      .then((res) => {
        this.setState({
          isLoading: false,
          dataSource: res.data
        })
      })
      .catch((err) => {
        alert("Error fetching data!");
      });
    
  }
BranOIE
  • 400
  • 4
  • 19
  • [This post probably answer your question](https://stackoverflow.com/questions/5806220/how-to-connect-to-my-http-localhost-web-server-from-android-emulator) – lblenner Oct 19 '20 at 19:52
  • So it says the ip address `10.0.2.2` is localhost. So where should I replace that in my url as I am using a virtual host? – BranOIE Oct 19 '20 at 21:36

0 Answers0