react-native: [TypeError: Network request failed] either with fetch API or axios on android

I have a problem with fetching an API on my code I use both fetch and axios but the result is same: [type error: Network request failed]

here is my code for fetch: useEffect(() => { fetch('https://jsonplaceholder.typicode.com/users') .then((res) => res.json()) .then((data) => { console.log(data) }) .catch((err) => console.log(err)) }, []);

I don’t use an emulator because my CPU doesn’t support vt-x. so I use a Xperia TX which has android 4.3 and I connect it over Wi-Fi to see my result. it work properly so far but the only problem is this API fetching.

React Native version:

0.63.2

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 11
  • Comments: 29 (1 by maintainers)

Most upvoted comments

Still I have this issue. Sometimes my https api works and sometimes it throws [TypeError: Network request failed]

IOS is working fine but not android

with no activity.

… “with no fix” would better represent the general problem

same here, those api’s are so unstable on android: i have another similar problem with them: https://github.com/facebook/react-native/issues/29267

Any update? Tried all above probable fixes but no success, facing the same Issue since a week. API working in postman and on iOS.

version 0.78.0

fetch("https://jsonplaceholder.typicode.com/todos/1") request sometimes hangs for 2 minutes, cannot find any solution

The fetch API is asynchronous. If it is blocking, it depends on your code. If it takes a long time (regardless your code is blocking) it depends on some wrong parameters/URL or connection issues or server side issues.

In any case the react-native api does not provide a detailed error information, which is the point of this open issue.

Hi @SohaibKtb @akeuk The issue got resolved for me after correctly installing the SSL Certificate.

how? i have same problems

@gvsakhil , can u please let me know the steps to install SSL certificate in Android & iOS?

Hi @SohaibKtb @akeuk The issue got resolved for me after correctly installing the SSL Certificate.