i am building a react native app, through rest-api in django framework, in test mode or in expo go the code is working fine but in, but after the apk build , data is not fetching
const fetchDataFromAPI = async (code) => {
setLoading(true);
setError(null);
if (ipAddress && profileCode) {
try {
const apiUrl = `http://${ipAddress}:8000/api/stock/?i=${profileCode}&s=${code}`;
setError(apiUrl);
const response = await Axios.get(apiUrl);
const stockData = response.data;
setData(stockData);
} catch (error) {
setError('error in fetching');
setData();
} finally {
setLoading(false);
}
} else {
setError('Ip Address Not Found');
}
};
after build always getting error in fetching
the total code in git repo is in following
2
Answers
Ensure that your app has the necessary network permissions. Add the following permission to your AndroidManifest.xml file within the
<manifest>
tag:Also verfify the Cross-Origin Resource Sharing (CORS) policy on your Django server.
Install the library
and then add it to your installed apps:
You will also need to add a middleware class to listen in on responses:
and specify domains for CORS, e.g.:
Refer the following answer for configuring CORS in django.
https://stackoverflow.com/a/35761088/7103882
the problem is this url:
http://${ipAddress}:8000/
Please read this link and it will help you https://stackoverflow.com/a/51892067/1308590