Network request failed Both App

Please provide the following:

  1. SDK Version:
    expo --version
    3.23.3

  2. Platforms(Android/iOS/web/all):
    Android

Network request failed

  • node_modules/whatwg-fetch/dist/fetch.umd.js:524:17 in setTimeout$argument_0
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:135:14 in _callTimer
  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:387:16 in callTimers
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:425:19 in __callFunction
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:112:6 in __guard$argument_0
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:373:10 in __guard
  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:4 in callFunctionReturnFlushedQueue
  • [native code]:null in callFunctionReturnFlushedQueue

I am using example.com/apis/faq as an example to request data get and post method both not working

import React from 'react';
import { AsyncStorage, Alert } from "react-native";
import constants from '../config/constants';
import { Success, Warning } from '../components/Message';

export const primeService = async (that, apiName, methodType = 'get', data = {}, redirectRoute = "", show = false, isLoader = true) => {
    try {        

        let params = {};
        
        if (methodType == 'post') {            
            params = {
                method: methodType,
                headers: {
                   // "Accept": "application/json",
                    //"Content-Type": "application/json",
                    'Content-Type': 'multipart/form-data',
                },
                body: data
            };
        
        }else{

            if (data) {                
                apiName = apiName + "?" + objToQueryString(data);
            }
            console.log(apiName);
            params = {
                method: methodType,
                headers: {
                    "Accept": "application/json",
                    "Content-Type": "application/json"
                }
            };

        }
        if(isLoader){
            that.setState({
                loading: true
            });
        }
    
        return response = await fetch(constants.API_ENDPOINT + apiName, params)
            .then((response) => response.json())
            .then((responseJson) => {                
                that.setState({loading: false});                
                if(responseJson.success){
                    if(show){                        
                        that.props.navigation.navigate(redirectRoute);
                        Success(responseJson.message);
                    }                          
                }else{
                    if(show){
                        Warning(responseJson.message);
                    }                    
                }                                                                
                return responseJson;
            }).catch((error) => {
                that.setState({ loading: false });
                console.log(error);                
                return error;                
            });
    } catch (errors) {        
        that.setState({ loading: false });
        console.log(errors);                
        return errors;
    }

}

/* To make query string */

function objToQueryString(obj) {
    const keyValuePairs = [];
    for (const key in obj) {
        keyValuePairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
    }
    return keyValuePairs.join('&');
}

I’m having the same problems here. I already searched for everything and nothing is working here. I already changed the way I was doing. I already changed the http://localhost:5000/api/users for http://myLaptopIP:5000/api/users and still not get any result. I’ve tried using another apis and that worked perfectly, and also when I type it on the postman but using the localhost:5000/api/users, I get all the results. I don’t know what kind of issue I’m facing. Does someone know how to check if my firewall is blocking the access?

Thanks a lot guys!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.