React Native Part 2 (Networking: Fetching Data)

“NETWORK_ERROR” problem! Application and Node backend both running :frowning: Please assist!! !

Additional capture

development.json
{
“assetsBaseUrl”: “http://192.168.0.1:9000/assets/”,
“port”: 9000
}

listings.js:
import client from ‘./client’;

const endpoint = ‘/listings’;

const getListings = () => client.get(endpoint);

export default {
getListings,
}

client.js:
import {create} from ‘apisauce’;

const apiClient = create({
baseURL: ‘http://192.168.0.1:9000/api/listings
});

export default apiClient;

I know mosh said it would not work but for me I set the baseUrl in client.js and the assetsBaseUrl in the back end project’s development.json file to local host (“http://localhost:9000/api”) and it worked for me.

I will try this and keep you posted :)! thx

no luck :(. Can you post your development.json, listings.js and listingsScreen.js?

Thanks. This is crazy :frowning:

Some random thoughts to investigate that may help you out:

Double-check your IP - I know that setups vary wildly however your posted IP sounds suspiciously like the IP for the gateway…

Can you connect to the backend using Postman?

1 Like

In the name of Larry David, “BINGO!!!”

wrong ip :frowning:

Thanks! :wink:

Hello,
I have the same “Network Error” problem. I am using windows and Android emulator. My Api (C# .Net core) is running fine locally at http://localhost:3000/odata/User but I get “Network Error” when trying to access it from the emulator.
Here is the code snippet:
const apiClient = create({

baseURL: “http://10.0.2.2:3000/odata”,

});

const getUser = () => apiClient.get("/User");

any ideas why I get the error?

Thanks!

Good days guys. I’m having the same problem as described above and I have tried possible solution but no result yet. why is this network error an issue because I did exactly what Mosh did?

have you checked your ip? Making sure it’s not the default gateway?

Please help confirm the ip address

Please how did you confirm the ip to be wrong

possibly run ipconfig on the command line and make sure you are not using the default gateway. maybe the ipv4 address.
good luck!!!

Hi,
I finally fixed the problem by using the ipv6 address. So my api address looks like this: http://[2600:8087:3500:cab6::e265]:5555/odata/user.
Run ipconfig, find your ipv6 address and put it inside square brackets like: http://[your ipv6]:your port/your api

Hope this helps.

It helps everyone!!! Good luck with the rest of the project.

I used IPv4, v6, localhost … nothing, I the array is empty!

Could you help me please, It doesn’t work using all IPV4, 6 whatever!

I would first do this:

  1. download his github project.
  2. go to folder/topic you are on C:\Part 2\Section 3- Networking\End (this will depend on where you downloaded the course material)
  3. run npm install in your directory which will download all of the npm dependencies
  4. then check: your baseURL with your ip. (maybe run ipconfig to see the possible address) (everyone’s ip is different’ish 192.168.0.0 <-who knows what your number will be

const apiClient = create({
baseURL: “http://192.168.0.14:9000/api”,
});

Good luck :slight_smile:

Hello Sir, Thank you for your try, of course, this is the last solution, I would understand why it didn’t work, by chance I found it last night !, it was something really ridiculous! I didn’t put () for the function loadListings in Listingscreen.js, now My screen still empty, the error is : [TypeError: undefined is not an object (evaluating ‘response.data’)]