0
fetch("http://httpbin.org/post")
   .then(response => response.json())
   .then(responseData => {})
   .catch(error => {
   Alert.alert("error:" + error);
});

I am trying to get fetches to work on Android. The sample code above get's called, however, it alerts "error:TypeError: Network request failed".

I have the INTERNET permission set in my Android manifest file. Not really sure what else to do. Is there a way I can find out the reason for the error?

EDIT When debugging, status is 0, timeout is 0, response is null, responseURL is undefined, and responseType is blob.

Wyatt
  • 493
  • 7
  • 18

2 Answers2

2

http is your issue ... https is needed

Hend El-Sahli
  • 6,268
  • 2
  • 25
  • 42
  • My PHP pages don't work with HTTPS for some reason. Is there any way I could get HTTP working? – Wyatt Mar 28 '19 at 19:44
  • check out this stackoverflow post https://stackoverflow.com/questions/51902629/how-to-allow-all-network-connection-types-http-and-https-in-android-9-pie – Hend El-Sahli Mar 28 '19 at 19:49
  • I don't have an XML folder in my project. Do I need to create one, and where must it be created? – Wyatt Mar 28 '19 at 20:27
  • C:\Users\USER\TestProject\android\app\src\debug\res – Wyatt Mar 28 '19 at 20:31
  • Found it in there. Thanks for your help – Wyatt Mar 28 '19 at 20:31
  • Hmm, my Android build is failing now after the manifest changes. "Execution failed for task ':app:processsDebugManifest'. Manifest merger failed" It also suggests adding 'tools:replace="android:networkSecurityConfig"' to . Any ideas? – Wyatt Mar 28 '19 at 20:43
1

Adding this to Manifest file solved my issue in Android 9

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">



    <application android:usesCleartextTraffic="true" tools:targetApi="28" />
Azhar
  • 20,500
  • 38
  • 146
  • 211