React Native APP With Expo Server Network Request Failed Error

  Kiến thức lập trình

I am new in REACT NATIVE APP , My app working fine in Expo server when I run the app using vs code and expo cli.
following points are cleared.

  1. My API is hosted at global server so there is not any network security I can easily access this from IP address on Same Device where I have installed the App.
    The issue is when I call the same api through app it says network request failed.
    But my same api is working fine in expo dev server.
    Please let me know what could be the issue is there anything like permissions???
    Here is my code also my api don’t have ssl its http.

handleLogin = async() => {
const { email, password } = this.state;

try {
  const url = `${API_ENDPOINTS.LOGIN}?username=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}&AppID=1`;
  const response = await fetch(url, {
    method: "GET",
    headers: {
      "Content-Type": "application/json",
    },
  });
  if (response.ok) {
    const data = await response.json();
    if (data.success && data.accessToken) {
    
      await AsyncStorage.setItem('userData', JSON.stringify(data));
      this.props.navigation.navigate('Home');
    } else {
   
      Alert.alert("Error", "Invalid username or password");
    }
  } else {
    console.error("Login failed:", response.statusText);
    Alert.alert("Error", "Login failed. Please try again.");
  }
} catch (error) {
  console.error("Login error:", error);
  Alert.alert("Error", error.message+ ' '+ API_ENDPOINTS.LOGIN);
}

};

I want my app to working fine if I create a build APK. I am using expo to create an aab file then aab file convertor to convert this to APK

LEAVE A COMMENT