question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetch fails with [TypeError: Network request failed] on Android with certain url

See original GitHub issue

Reproduced on React-Native 0.21, 0.22.0 , and 0.22.2

fetch('https://api-dev.semios.com/', {
     method: 'POST',
   }).then((response) => {console.log(response)}).catch((error) => {console.log(error)})

fails with [TypeError: Network request failed] only on Androidthis works properly on iOS Reproduced with https://rnplay.org/apps/MUs3SQ

I/ReactNativeJS( 2790): [TypeError: Network request failed] 

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
ericmasiellocommented, Jul 13, 2016

I’m having a similar issue but mine isn’t even related to SSL. I’m just trying to run the example fetch from the RN docs calling out to http://facebook.github.io/react-native/movies.json. When I try it out on the simulator its fine. But when I plug in my device and and deploy it to that using react-native run-android it can’t seem to successfully load the data.

fetch('http://facebook.github.io/react-native/movies.json')
      .then((response) => response.json())
      .then((responseJson) => {
        //works fine in simulator
        this.setState({title: responseJson.title})
      })
      .catch((error) => {
        //hits this everytime on the actual device
        console.error(error);
      });

Any suggestions?

3reactions
javamonncommented, Apr 14, 2016

Adding in my case here: Similar situation as OP, https URL failing with [TypeError: Network request failed] on Android, successful on iOS, certificate showing as valid in browser.

In my case, had SSL setup on nginx with Let’s Encrypt but left out the intermediate certificates, i.e. I was using the cert.pem instead of fullchain.pem. This thread has some more info. Once I got the intermediate cert configured correctly, Android/OkHttp accepted it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP Fetch fails with "TypeError: Network request ... - GitHub
There are 83 issues opened and unanswered about network requests failing with this generic error. The main causes of the pain are: Not...
Read more >
Fetch() returns "TypeError: Network request failed" for specific ...
As for the error you're getting, TypeError: Network request failed from within an Android app -- it's very possible that your Anrdoid app...
Read more >
Improve "TypeError: Network request failed" error message
I get error messages when I make a request with fetch api on android (btw the same code is working perfectly fine on...
Read more >
How to solve 'TypeError: Network request failed' in React ...
two thing : 1. add android :usesCleartextTraffic="true" in your Android manifest android /app/src/main/AndroidManifest.xml2.
Read more >
[typeerror: network request failed] - You.com | The AI Search ...
Since your Android device has an IP of its own, you need to point the URL to your computers IP address instead of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found