#Someone know how to fetch content of a localhost php file in expo react?

1 messages · Page 1 of 1 (latest)

inland shell
#

i'm losing my mind trying to do this

#

i need to do this because my programming teacher is making us do it

#

so i will say what i did thus far

#

so my teacher told me install a programm called rngok to create a tunnel and i did

#

then i just made a function in expo like this

#

async function get() {
try {
const response = await fetch(
"https://fa61-189-44-91-218.ngrok-free.app/miniSprint6/api/testeApi.php/CLiente",
{
method: "GET",
headers: {
"Content-Type": "application/json",
}//
}
);
const data = await response.json();

  alert("GET realizado com sucesso!");

  return JSON.strigify(data);
} 

catch (error) {
  console.error("Erro ao executar solicitação GET:", error);
  alert(`${error}`);
}

}

#

and it's giving this error

turbid pike
#

if you go to that url with a browser, does the content show up?

#

the code looks fine on first glance

inland shell
#

the error:TypeError: NetworkError when attempting to fetch resource.

inland shell
#

let me test it again

turbid pike
#

also - if you change that url to one where you know that you get a response, does that work?

#

though thats not json

neat atlas
#

:3

turbid pike
#

you can also try to run this in your browser:

fetch("https://fa61-189-44-91-218.ngrok-free.app/miniSprint6/api/testeApi.php/CLiente").then(r => r.json().then(console.log))
inland shell
inland shell
neat atlas
#

(This one might be obvious, but you never know) Make sure that the server it runs on has a network connection

inland shell
#

i think this might be the problem

turbid pike
#

that could be it yea

neat atlas
#

💀

#

Yep

inland shell
#

any of you heard of nrgok?

#

my teacher just installed it in in my pc

turbid pike
#

yes, but never used it like this

inland shell
#

it's supposed to let me use localhost in expo

inland shell
inland shell
turbid pike
#

never used expo either but I have a react project here, let me try to forward it using ngrok

inland shell
#

it should be the same thing

#

the only difference is that expo runs on browser

turbid pike
#

for me it works

#

lemme try in incognito

inland shell
#

hm

turbid pike
#

also works in incognito, so it's nothing in my browser

#

how do you open your thing using ngrok

inland shell
#

that's weird

turbid pike
#

like what command do you use?

inland shell
turbid pike
#

mine is running on port 3000 so I use ngrok http 3000 but it should do the same

#

strange, looks like it should work

inland shell
#

pmao

#

lmao

turbid pike
#

haha all good

inland shell
#

my teacher got it to work on his example project but i can't replicate it on mine ;-;

#

now it's not working even in his project anymore whataheck

turbid pike
#

lol