title: Network request failed when trying POST request in React-Native
body: <p>I'm trying to POST request to my local server from my React native app, and get an error.</p>
  
  <p>I built a general httpMethod function</p>
  
  <pre><code>export async function httpMethod(req) {
    try {
      var response = fetch(`${apiUrl}${req.api}`, {
        method: req.method,
        headers: req.headers
          ? req.headers
          : {
              'Content-Type': 'application/json'
            },
        body: JSON.stringify(req.body)
      });
      return response;
    } catch (error) {
      console.error(error);
    }
  }
  </code></pre>
  
  <p>and I call it from this method:</p>
  
  <pre><code>export async function registerUser(props) {
    try {
      const { email, password } = props;
      let api = `/users`;
      return await httpMethod({
        method: 'POST',
        api,
        body: { email, password }
      });
    } catch (error) {
      console.error(error);
    }
  }
  </code></pre>
  
  <p>the URL is <code>http://0.0.0.0:9000/users</code></p>
  
  <p>when trying to post this through postman, everything works fine:
  <a href="https://i.stack.imgur.com/vyclU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vyclU.png" alt="enter image description here"></a></p>
  
  <p>after adding some console logs to make sure my HTTP request URL and params are fine I get this error:</p>
  
  <pre><code>HTTP POST  request to -- http://0.0.0.0:9000/users
   req.body: {"email":"Test@gmail.mmm","password":"@Aa123456"}    
   headers: undefined
  
  Network request failed
  - node_modules\react-native\Libraries\vendor\core\whatwg-fetch.js:504:15 in XMLHttpRequest.xhr.onerror
  - node_modules\event-target-shim\lib\event-target.js:172:38 in XMLHttpRequest.dispatchEvent
  - ... 9 more stack frames from framework internals
  </code></pre>
  
  <p>what am I doing wrong?</p>