title: How to fix network error in react-native when access localhost api
body: <p>We're trying to connect to an API (.net core 2.2) from react-native (version 0.59), via localhost, both apparently running on the same ip, different ports, react-native on port 8080, and the api on the 44344, the issue happens the moment we fetch the url from react-native</p>
  <p>We’ve also tested running the url from Postman and everything seems ok, also from any of the web browser installed (safari/chrome), even we tested the browser INSIDE react-native iOS, and it works.</p>
  <p>Any api running outside localhost works perfectly, is the localhost were we failed.</p>
  <pre><code>Network request failed.
  
  onerror
      whatwg-fetch.js:504:29
  dispatchEvent
      event-target.js:172:43
  setReadyState
      XMLHttpRequest.js:580:29
  __didCompleteResponse
      XMLHttpRequest.js:394:25
  emit
      EventEmitter.js:190:12
  __callFunction
      MessageQueue.js:366:47
  &lt;unknown&gt;
      MessageQueue.js:106:26
  __guard
      MessageQueue.js:314:10
  callFunctionReturnFlushedQueue
      MessageQueue.js:105:17
  callFunctionReturnFlushedQueue
      [native code]:0
  </code></pre>
  <p>Part of the code (function) that fetch the api, very simple (for now)</p>
  <pre class="lang-js prettyprint-override"><code>async Submit(){
    //GET METHOD
    try {
          let response = await fetch('https://192.168.1.56:44344/api/values');
          let responseJson = await response.json();
          return Alert.alert(JSON.stringify(responseJson));
    } catch (error) {
          console.error(error);
    }
  }
  </code></pre>
  <p>Ok first of all, we've tried EVERY possible solution,to connect my react native app to my .net core api rest, both running in localhost, this is the list so far, of the things that we've tried so far, and still no result.</p>
  <ul>
  <li>Localhost</li>
  <li>127.0.0.1</li>
  <li>Computer ip (network ip not mac address)</li>
  <li>React Native blank project (from the ground up)</li>
  <li>API .net core blank project (from the ground up)</li>
  <li>Running snack expo + api .net core</li>
  <li>ip forwarding (We can't do that do to our job policies/Not the solution we're looking for)</li>
  <li>http/https</li>
  <li>Different ports</li>
  <li>Android and ios permissions from react-native</li>
  <li>Same network different ip (this sorta worked, but we don't know exactly why it doesn't work running both react-native and the api in the same ip (localhost))</li>
  <li>10.0.2.2 (for android)</li>
  <li>Enable cors on api .net core (but apparently this doesn't work on native apps, only for web)</li>
  <li>Expose the ip through ngrok/serveo (We can't do that do to our job policies/Not the solution we're looking for)</li>
  <li>Frisbee</li>
  <li>Axios</li>
  <li>Websocket (We can't do that do to our job policies/Not the solution we're looking for)</li>
  <li>XMLHttpRequest (status code error 0)</li>
  <li>Firewall/proxy (our network is free from firewalls and proxies)</li>
  <li>Web browser plugins (deactivated and/or uninstalled)</li>
  <li>Cache/cookies</li>
  <li>Docker (We can't do that do to our job policies/Not the solution we're looking for)</li>
  <li>Reboot my macbook pro</li>
  </ul>
  <p>we expect react native to fetch the api, so we can continue with the office 365 login authentication.</p>
  <p>EDIT: I just discovered that fetching the machine ip (this time running windows), with my ip being 192.168.0.9 both on the api and the react native, the fetch result showed me the 10.0.2.2:80 in the header of the json response. I suppose it is the &quot;localhost&quot; ip from react native. How am I supposed to fetch an ip from localhost if react native is not letting me to do so?</p>
  <p>EDIT: We had to go for plan B this time around, we've made it work with a docker on the api, but I need a solution for this problem. I'm 99% sure the issue is react-native and nothing else.</p>
  <hr>
  EDIT: After all these weeks one of my colleges managed to solve it. First of all, we couldn't make the firewall in my macbook pro work properly. Second, we solved that and found out our api was having issues. He found out the redirection was on https, and the certifications weren't working properly, so he changed this 
  <pre><code>&quot;applicationUrl&quot;: &quot;http://192.168.0.114:5001;https:192.168.0.114:5001&quot;
  </code></pre>
  <p>to</p>
  <pre><code>&quot;applicationUrl&quot;: &quot;http://192.168.0.114:5001&quot;
  </code></pre>