I have a .net 8 maui app that connects to a webapi (on localhost).
Both apps are running from the same project.
I'm able to connect to the api from the emulator, but cannot connect when running the app from my local device.
I access the api using https://10.0.2.2:"port" - is there something I need to do to give my local device access to make calls to localhost?
Any advice will be great.
Update:
In order to get the working on your local device, first get the ipv4 for your connection, and use this as the base address for your maui application
Secondly, use this same ip address in launchsettings.json "https://ipv4:port" and make sure both are running
If you are testing your application from a real android device, then you need to put the IP address of your PC while you are trying to connect to your server through APIs. Besides, you also need to make sure they're on the same network.
So, you can recheck the following things:
1.Make sure that the PC (where you are running the server) and the Android device (where you are testing your application) are on the same network (e.g., connected with the same Wifi network).
2.Make sure you are connecting to the IP address of your PC where the server is running. For example, the IP address of your PC is 192.168.1.5. Then, you need to connect to this IP address and call your API as following:
http://192.168.1.5:8000/api/update/68/
You can get the Ip
by ipconfig
command:
3.Make sure you could accept the requests to the port 8000 in your PC. Check your Firewall configuration if it is blocking any incoming requests to the 8000 port. If it is found blocking, then please allow an incoming request to the 8000 port using the following.
sudo ufw allow 8000/tcp
4.Make sure you're using http
only when running server locally.