Postman Screenshot of dot net core API
Postman fetches the data from my dot net core API but I cannot get the data in React native using the same API. I tried everything like changing port number etc.
React Native API Request
useEffect(() => {
const getData= async () => {
try {
const response = await axios.get('http://10.0.2.2:54669/DoctorMaster/Getalldoctorssearch/1062');
setAppointments(response.data);
setIsLoading(false);
console.log(response.data);
} catch (error) {
console.log(error);
}
}
getData()
}, [setAppointments, setIsLoading]);
4
Answers
Solution: All of the answers did not work for me, I used a visual studio extension called Conveyor by keyoti to solve the issue, this extension allow me to use the API outside of localhost, it will show you the remote URL, use that url to call API from your mobile application
Please follow the below structure
Be aware that React Native refuses HTTP requests instead of HTTPS requests by default:
To handle HTTP requests in Android see this post
To handle HTTP requests in iOS see this post
You are trying to fetch data from localhost which your mobile device won´t be able to fetch the url. You need to publish your API on a Web Server, and then you will be able to fetch the data