Ни одно из этих решений не работало, так как везде люди ссылались на "localhost", который я не использовал, я нашел решение, которое работало для меня, для которого вам нужно добавить требуемый хост в следующем файле
android/app/src/debug/res/xml/react_native_config.xml
.
Вот как выглядит мой xml сейчас:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="false">localhost</domain>
<domain includeSubdomains="false">10.0.2.2</domain>
<domain includeSubdomains="false">10.0.3.2</domain>
<domain includeSubdomains="true">facebook.github.io</domain>
</domain-config>
</network-security-config>
После чего начал работать мой нижеприведенный запрос:
fetch('http://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
Alert.alert(JSON.stringify(responseJson));
});
.catch((error) => {
console.error(error);
});