I'm developing a mobile app with React Native, and have a REST API in Django at the backend. I want to make a POST request from the app to my API.
Code
function sendDpi() {
const requestOptions = {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
dpi: imageDpi,
}),
};
fetch('http://127.0.0.1:8000/', requestOptions)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => {
console.log(error);
});
}
When sendDpi() is called by my app, I get [TypeError: Network request failed].
127.0.0.1:8000 is where my Django app is running. I've tried using my IP address (as pointed out by this answer) as well.
I've also modified android/app/src/main/AndroidManifest.xml to include android:usesCleartextTraffic="true".