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

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] 

About this issue

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

Commits related to this issue

Most upvoted comments

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?

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.

This blog post might describe what’s happening: http://steveliles.github.io/android_ssl_certificate_not_trusted.html