✅ Android Emulator in MAUI is not connecting to webAPI
Hey there! I am trying to get data using web API but this exception raises everytime: [0:] Exception when accessing http://10.0.2.2:5191/api/SalesOffice/offices-with-property-counts: Connection failure
I did the network_security_config and everything but nothing worked ..
it works when I tried it on windows app, but android emulator gives the above exception
9 Replies
network_secuirty_config.xml
AndroidManifest.xml
The class that handles the request
$mauiapi
How to access WEB API using dev tunnels in MAUI? Click here to read the dev blog post!
The alternatives without dev tunnels are, A and B(you dont need to do both!):
A) By enabling
UsesCleartextTraffic
and running the API without HTTPS, type $mauiapihttp
for more info.
B) By overriding the native http handler to support localhost and self signed CA, type $mauiapihttps
for more.did u also configure your api to run over http?
did u also configure it to bind to your ip 10.0.... or all ips with 0.0.0.0
the simplest route is just using dev tunnels then u dont need to do any of these.
Android emulators are not directly connected to your host machine, https://docs.lextudio.com/blog/how-to-let-android-emulator-access-iis-express-f6530a02b1d3
Half-Blood Programmer
How to Let Android Emulator Access IIS Express
This post is about how to let Android emulator access web apps hosted on IIS Express.
with MAUI you can directly access 127.0.0.1, but there are some caveats to it
so if u just use the local network ip u have a way easier time doing it if u dont want dev tunnels
which is just running the api in http instead of https with the proper ip setup or just 0.0.0.0
Yes if you mean this one,
I'll try it, thank you so much everyone!
Dev Tunnel worked, Much appreciated. 🙏🏾
@.Abdulrahman glad it worked, and yes I meant that file, u would have to change the localhost to either ur local ip or 0.0.0.0 which means bind to all interfaces
but with devtunnels u dont need to do any of that.
Use the /close command to mark a forum thread as answered