Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Http request dont work in Android

Tags:

react-native

Working with requests to the server using Fetch and also using Axios, when running it on Android emulator/devise it shows me the following error:

enter image description here

this is the request code:

fetch(URL,{
      method: 'POST',
      headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
                email: userEmail,
                password: userPassword
            }),

        })
        .then((response) => response.json())
         .then((responseJson)=>{
             Alert.alert("bien");
       console.warn(responseJson);
             })
         .catch((error)=>{
         console.error(error);
     console.warn(error);
   });
like image 625
mariovzc Avatar asked Aug 23 '26 07:08

mariovzc


1 Answers

Since Http request doesn't work in the latest android updates I think after 28 arrived. So you have to add the following attributes to your AndroidManifest.xml

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

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

        <application
           android:usesCleartextTraffic="true"> 

                // ----------------

        </application>
   </manifest>
like image 127
iamsr Avatar answered Aug 26 '26 07:08

iamsr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!