'Axios and Fetch is not working for my react Native app for android
I am always getting Network error alert for the below API axios get request. Please suggest what is wrong with my url given. I read so many posts and i think my url is not correct. I have added my ip with port number in between of https:// and api. Kindly help what needs to be updated in the code. React Native-Axios-Android Emulator
import React from 'react';
import { View, Text, Button } from 'react-native';
import axios from 'axios';
function WelcomePage({ navigation }) {
const dataFetch = async () => {
try {
const response = await axios.get('https://192.168.1.4:5554/reactnative.dev/movies.json');
alert(JSON.stringify(response.data));
}
catch (error) {
alert(error.message);
};
}
return (
<View>
<Text>Welcome!</Text>
<View>
<Button
title="Fetch Name and DOB"
onPress={dataFetch}></Button>
<Text></Text>
<Button
title="Go to Profile Page"
onPress={() => navigation.navigate("Cart")}></Button>
</View>
</View>
);
}
export default WelcomePage;
Solution 1:[1]
You are using https://192.168.1.4:5554/reactnative.dev/movies.json, but localhost doesn't support https, change to http://192.168.1.4:5554/reactnative.dev/movies.json it should work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andre Angeloni |
