#Someone know how to fetch content of a localhost php file in expo react?
1 messages · Page 1 of 1 (latest)
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
if you go to that url with a browser, does the content show up?
the code looks fine on first glance
the error:TypeError: NetworkError when attempting to fetch resource.
it shows up
let me test it again
also - if you change that url to one where you know that you get a response, does that work?
though thats not json
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))
lemme try
this did work
aight
(This one might be obvious, but you never know) Make sure that the server it runs on has a network connection
that could be it yea
yes, but never used it like this
it's supposed to let me use localhost in expo
i see
do you know of a way i could maybe fix this?
never used expo either but I have a react project here, let me try to forward it using ngrok
alright thanks
it should be the same thing
the only difference is that expo runs on browser
hm
also works in incognito, so it's nothing in my browser
how do you open your thing using ngrok
that's weird
like what command do you use?
ngrok http 80
mine is running on port 3000 so I use ngrok http 3000 but it should do the same
strange, looks like it should work
sorry for leaving you on read my teacher started to show me how to do the thing in my pc
pmao
lmao
haha all good
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
lol