Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29588

React Native (Android) with Django Rest Framework - TypeError: Network Request Failed

$
0
0

Trying to set up fetch request for the first time in react native, but I end up with an error screen. I have already made sure my server is running on my inet address but the device just wouldn't send the fetch request.

The Django server is running on 192.168.0.10 (port 8000) which is my inet address. Also, I am using an externally connected Android device (via USB).

Registration.js


  componentDidMount() {
    fetch('http://192.168.0.10:8000/api/registration1/', {
    // fetch('http://10.0.2.2:8000/api/registration1/', {
      method: 'GET', // or 'PUT'
      headers: {
        'Content-Type': 'application/json',
        Accept: 'application/json',
      },
    })
      .then(response => {
        console.log('I AM IN');
        return response.json();
      })
      .then(data => {
        console.log('Success:', data);
      })
      .catch(error => {
        console.error('Error:', error);
      });

    console.log(' COMPONENT DID MOUNT OVER');
  }

I have enabled http support in my android.manifest file.

Android.manifest

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

    <uses-permission android:name="android.permission.INTERNET" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:usesCleartextTraffic="true"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

    </application>

</manifest>

Here's the error I get:

enter image description here


Viewing all articles
Browse latest Browse all 29588

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>