✅ How can I connect my Xamarin app to my local API?
I have an API running in my machine and for test purposes I only need it to be local.
33 Replies
It doesn't work with localhost, nor with my IpAdress
Calling it in my own machine also doesnt work if I change the Ip from localhost to My IP
I don't know about Xamarin but in MAUI you have to do some overly annoying things to get localhost working
let me see if I can find hte thread
https://discord.com/channels/143867839282020352/1221703280204451932/1221830944231657603
see if its something related to this if not just ignore me 😉
or the simplest u just disable https in the api
Turned https off...
the problem remains, and as well, even in postman in my own machine I cannot call my own IpAdress
postman doesnt let u call localhost?
This is so weird, I dont remember changing my config on these terms
localhost yes, but when I place my raw IP it ignores
well u just need localhost
from xamarin as well
but what is the other ip ur trying to use?
192...?
127...?
or real external ip
I tried 192, 127
i tried typing random numbers to see if I fool the xamarin app
I will try again with http tho
u have to add permissions to the manifest
Not permitted. am I missing some file configuration here
https://stackoverflow.com/questions/67071052/how-to-fix-cleartext-http-traffic-to-x-not-permitted-in-xamarin-android
make sure u wrap it for debug only thou
Its a test for a vacancy... nothing will go public
I mean the code is simple enough so why not
anyway did it work?
nope
from the link above?
I have my phone connected via USB, I dont know if makes any difference
ah ok you're not using the emulator
u would have to acccess it via the network ip it gives your phone then
check the network details
I tested with the IPV4
this is the one you reffering to?
I mean u can just go to the mobile configuration and check
yes ipv4
that page would tell u
so if it is 192 something
then u would use your local 192 to access it
then u would have to add it to your api
which is probably only listening to localhost
for such scenarios MS created the dev tunnels that are easy accessable in visual studio.
ah true that is also an option forgot they added that
but you can just add this line to your api's appsettings.Development.json as an alternative
change port to the port in your .http file
then it will bind to localhost and other ips in your network card
for the api
not even the f tunnels are working
And to connect to this one in my Mobile I access 0.0.0.0?
nothing worked 🙂
WORKED!!!
I'm not aware of what I did, but it worked. Thanks a lot guys you're awesome
tbh now, I removed the https and retried sending to my IPv4
and wroked 👍
nice 😉 yeah 0.0.0.0 just means bind to all my available ips
so imagine u have:
192.168.0.100 as your internal ip
127.0.0.1 as localhost
1x.xxx.xxx.xxx as your external ip
it will try to bind to all of those on the pre-defined port 😉
so u would be able to access it on any of those
by default it only binds to localhost
which is why u were unable to access it before
------=======
I strongly suggest thou, that u move to MAUI if u haven't develop too much of the app yet
xamarin is pretty much dead
and MAUI took its place
Use the /close command to mark a forum thread as answered
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
do u think its worth it? its a lot of text
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
this was the second time ever
and dev tunnels exists now
so I am unsure this would be worth the trouble over just doing dev tunnels
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
thx for the suggestion thou I will look into writting something I been wanting to make a tag
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View