Calling function : This is where I am creating a API call.
onAddMenuApi(formData) {
return fetch(UserManagerIns.getUserData('API_URL') + 'menu-item-add', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data',
},
body: formData,
})
.then(response => {
if (!response.ok) {
throw new Error(response.status);
}
return response.json();
})
.then(myres => {
console.log('Item Add API data::::: ' + JSON.stringify(myres));
return myres;
})
.catch(error => {
return error;
});
},
Setting Parameters : This is where I am make a API call after this and set a formData Parameter.
let params = {
title: this.state.title,
price: this.state.price,
menu_cat_id: this.state.menu_cat_id,
};
let formData = new FormData();
for (var k in params) {
formData.append(k, params[k]);
console.log('My Data :: ' + params[k]);
}
formData.append('image_url', {
uri: this.state.ImageSource,
name: this.state.filename,
type: this.state.type,
});
In response I am getting "Network request failed".
I have added in AndroidManifest file the line : android:usesCleartextTraffic="true"
I have added network_security_config.xml as well but it is not working.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>