React Native Android Fetch failing on connection to local API

前端 未结 9 1864
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 22:08

I\'m using the fetch API in my react-native Android app to make requests to a local API. I usually query said API from react web apps at http://localhost:8163.

I\'m t

9条回答
  •  星月不相逢
    2020-11-28 22:52

    If you are using Metro Bundler in Expo Developer Tools Use CONNECTION LAN ip address Sample image Metro Bundler

    How to used in react native

        getfetch = () => {
        return fetch('http://LAN-IP-ADDRESS-HERE:4300/customers/',{
              method: 'GET',
              headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
              }
            })
        .then((response) => response.json())
        .then((responseJson) => {
    
           console.log(responseJson);
    
        })
        .catch((error) =>{
            console.error(error);
        });
    }
    

    Sample image REST API using postman

    Sample image POSTMAN

    Hopefully this is helpful :)

提交回复
热议问题