title: React Native network error in POST request when adding a body
body: <p>it's me again.</p>
  
  <p>I'm learning react native, for now im trying to upload a file, the api is already tested using postman and it does work so I wrote this code:</p>
  
  <pre class="lang-js prettyprint-override"><code>import * as DocumentPicker from 'expo-document-picker';
  
  async login () {
      let response = await DocumentPicker.getDocumentAsync({type: '*/*'})
  
      const data = new FormData();
      data.append('file', response)
  
      // Fetch attempt ----------------------------------------
      fetch("http://192.168.0.3:8000/api/file", {
        method: "POST",
        headers:{  
          "Content-Type": "application/x-www-form-urlencoded",
        },
        body: data
      })
      .then(response =&gt; response.json())
      .then(response =&gt; {
        console.log("upload succes", response);
      })
      .catch(error =&gt; {
        console.log("upload error", error, JSON.stringify(error));
      });
  
      // Axios attempt ----------------------------------------
      axios.post('http://192.168.0.3:8000/api/file', data, { headers:{ "Content-Type": "application/x-www-form-urlencoded"} } )
      .then(res =&gt; {
        console.log("goddaamittt wooork", res)
      })
      .catch(error =&gt; {
        console.log("error", error, JSON.stringify(error))
      });
    }
  </code></pre>
  
  <p>When I remove the body and headers from that request it actually returns what the api should return when you try to POST to it without a 'file', some message "{'fileName': 'A file is required'}" but adding it to it I get a network error, the error I get when using fetch it:</p>
  
  <pre><code>upload error [TypeError: Network request failed] {"line":24646,"column":31,"sourceURL":"http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=android&amp;dev=true&amp;minify=false&amp;hot=false"}
  </code></pre>
  
  <p>when it reaches the axios attempt it says something like this:</p>
  
  <pre><code>[Unhandled promise rejection: TypeError: Network request failed]
  </code></pre>
  
  <p>I tried everything I knew, I need some help!</p>
  
  <p>Idk if it is important but here is what DocumentPicker returns when I pick a file:</p>
  
  <pre><code>Object {
    "name": "FB_IMG_1573232116651.jpg",
    "size": 32482,
    "type": "success",
    "uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Fjsonplaceholder-bcb4c1c6-b37d-4634-99a5-3410d9b8654e/DocumentPicker/db8d78dd-2587-40e4-aed9-656c36df29f4.jpg",
  }
  </code></pre>
  
  <p>This is the error I get when I remove the body from the axios request</p>
  
  <blockquote>
    <p>error [Error: Request failed with status code 400] {"config":{"transformRequest":{},"transformResponse":{},"headers":{"Accept":"application/json, text/plain, <em>/</em>"},"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"method":"post","url":"<a href="http://192.168.0.3:8000/api/file" rel="nofollow noreferrer">http://192.168.0.3:8000/api/file</a>"},"response":{"data":{"message":"File is required"},"status":400,"headers":{"map":{"cache-control":"public, max-age=0","x-robots-tag":"noindex","x-debug-token-link":"<a href="http://192.168.0.3:8000/_profiler/54e68c" rel="nofollow noreferrer">http://192.168.0.3:8000/_profiler/54e68c</a>","x-debug-token":"54e68c","link":"<a href="http://192.168.0.3:8000/api/docs.jsonld" rel="nofollow noreferrer">http://192.168.0.3:8000/api/docs.jsonld</a>; rel=\"<a href="http://www.w3.org/ns/hydra/core#apiDocumentation" rel="nofollow noreferrer">http://www.w3.org/ns/hydra/core#apiDocumentation</a>\"","content-type":"application/json","x-powered-by":"PHP/7.2.4","connection":"close","date":"Fri, 08 Nov 2019 17:54:12 GMT","host":"192.168.0.3:8000"}},"config":{"transformRequest":{},"transformResponse":{},"headers":{"Accept":"application/json, text/plain, <em>/</em>"},"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"method":"post","url":"<a href="http://192.168.0.3:8000/api/file" rel="nofollow noreferrer">http://192.168.0.3:8000/api/file</a>"},"request":{"url":"<a href="http://192.168.0.3:8000/api/file" rel="nofollow noreferrer">http://192.168.0.3:8000/api/file</a>","credentials":"omit","headers":{"map":{"accept":"application/json, text/plain, <em>/</em>"}},"method":"POST","mode":null,"referrer":null,"_bodyText":""}},"line":178773,"column":26,"sourceURL":"<a href="http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=android&amp;dev=true&amp;minify=false&amp;hot=false" rel="nofollow noreferrer">http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=android&amp;dev=true&amp;minify=false&amp;hot=false</a>"}</p>
  </blockquote>