paul netia
paul netia

Reputation: 11

LOG [TypeError: Network request failed]

I am new to react native. Every time i try to fetch i get this error

[TypeError: Network request failed]

below is the code:

  fetch("http://192.168.20.137:3000/posts", {
    method: "POST",
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json",
    },
    body: JSON.stringify(memberID),
  })
    .then((res) => res.json())
    .then((data) => Alert.alert(data))
    .catch((err) => console.log(err));
}; ```

Upvotes: 0

Views: 1591

Answers (1)

Hitesh Prajapati
Hitesh Prajapati

Reputation: 1411

Add these lines of code inside AndroidManifest.xml

<application
  ....
  ....
 android:usesCleartextTraffic="true">

Then, try to run your code in a real physical device, instead of emulator, to run on physical devices - connect your usb and try to run npx react-native run-android

Upvotes: 1

Related Questions