fetch

Why React Native Android Fetch failing on access to localhost



Sharing buttons:

hi everyone and welcome to a busy step

tutorials and this is alpha and this

tutorial about the most common question

which is how to access localhost from

the emulator and this question also

related to the most common issue which

is network requests failed

now with this tutorial to figure out why

this issue happen and how we can solve

this if you interested let's see what we

can do

hi again to fix this issue

let's first know what happened behind

the scene take a look at my code which

is just a symbol flat list to render

tasks tasks came from fetch API which is

fetching the task is from ABI and - -

duze and return it as a JSON there is

the database test data will has a

two-dose table with some tools and this

is peach be code here in the ABI - peach

be I select to those and return it as a

JSON it is very simple

ABI to illustrate what happened behind

the scene now let's see what happened

and why it happened when you write

localhost you use the local host and

local host point in Windows to 127.0.0.1

and also it is the same for the Apache

a patch server to render PHP files so

there is a confusion here you use a

local host which is using the same IP

for the emulator and Apache this caused

the error it may be another I be on the

Mac simulator but it is the same concept

the problem happen when you use the same

IP for the emulator and for the server

which may be I is for Microsoft so to

solve this problem you want to change

the IP for the server now this is a time

to fix this issue step one get the

static IP or the internal IP for your

computer in my Windows computer I will

go to comment comment prom bit and just

type Ib

content here I will go to ipv4 address

this is the IB and just mark and copy it

step to change this IB and the port into

your fetch a bi here I will replace

localhost with this ABI at the port

which is 80 or you can choose what you

want for this port after this let's go

to step 3 which is it changing the IP

and the port into HTTP config into

Apache server I'm using zamp and

you can use this method with any server

I will go to them Apache config HTT TBD

dot-com fed edit with new bed and go to

lesson 80 and I will hash and to change

we add lesson and this is the IP with 80

Save and close

stop the Apache and my sequel and start

again

and it's ok

step 4 just check if your firewall able

to access this program this application

to this IP and port fire wall allow a

nap through windows check here and in

the Apache

this is Apache and private connection is

enabled now after this let's check the

new IP in the browser to access a new IP

when I go to localhost - duze ABI and

refresh I can't access to act let's

check the new IP and press enter and

that's ok it's working good also in PHP

myadmin

I will change it to the new IP and

that's ok it's also working God now

let's check if the error is still or

affected I will open the emulator and

remove

this error and reload again and that's

okay the issue is going you can now

access the JSON no problem with JSON is

at position zero this is a problem in my

JSON but the network connection is fix

it now finally I hope this tutorial is

save your time and help you to

understand the issue and if you liked

this tutorial please like leave a

comment if you have a question and

subscribe for the new tutorials thank

you for watching see you next bye