title: React Native on Android, ajax call with fetch fails
body: <p>I am developing an Android app using React Native. I am testing my app on a Galaxy Nexus API 23 that is being emulated in Android Studio, running on a mac.</p>
  
  <p>I wish to allow users to share information with each other. I am running a webserver with php and mysql, and I want the app to make requests to the server to share data between users.</p>
  
  <p>I am trying to make a POST request to my development server using the Fetch API. My js code is below: </p>
  
  <pre><code>var AjaxEngine = {
      test: function() {
              return fetch('http://10.0.2.2/test.json')
                  .then((response) =&gt; response.json())
                  .then((responseJson) =&gt; {
                      console.log(responseJson);
                      return responseJson.movies;
                  })
                  .catch((error) =&gt; {
                      console.error(error);
                  });
          }
  };
  </code></pre>
  
  <p>called by <code>AjaxEngine.test();</code></p>
  
  <p>In my emulator I receive the following error: </p>
  
  <blockquote>
    <p>ExceptionsManager.js:70 TypeError: Network request failed
            at XMLHttpRequest.xhr.onerror     (<a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:23711:8" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:23711:8</a>)
            at XMLHttpRequest.dispatchEvent (<a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:9740:15" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:9740:15</a>)
            at XMLHttpRequest.setReadyState (<a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:25157:6" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:25157:6</a>)
            at XMLHttpRequest.__didCompleteResponse (<a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:25015:6" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:25015:6</a>)
            at <a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:25090:52" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:25090:52</a>
            at RCTDeviceEventEmitter.emit (<a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:8977:23" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:8977:23</a>)
            at MessageQueue.__callFunction (<a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:7065:23" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:7065:23</a>)
            at <a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:6969:8" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:6969:8</a>
            at guard (<a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:6917:1" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:6917:1</a>)
            at MessageQueue.callFunctionReturnFlushedQueue (<a href="http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:6968:1" rel="nofollow noreferrer">http://localhost:8081/index.android.bundle?platform=android&amp;dev=true&amp;hot=false&amp;minify=false:6968:1</a>)</p>
  </blockquote>
  
  <p>test.json consists of:</p>
  
  <pre><code>{
      "message":"hello world"
  }
  </code></pre>
  
  <p><strong>The request is successful when I replace <code>'http://10.0.2.2/test.json'</code> with <code>'http://facebook.github.io/react-native/movies.json'</code>, so the function itself is ok.</strong> </p>
  
  <p><code>'http://localhost/test.json'</code> and <code>'http://127.0.0.1/test.json'</code> both load in a web browser, <code>curl</code>, and <code>wget</code>. I have also tried replacing the 10.0.2.2 with 127.0.0.1. I have also tried using my local ip (129.xxx.x.x)</p>
  
  <p>What do I need to do to make these requests work? How do I access my development server running on localhost from the emulated android app?</p>