I created the simplest GET (spring boot backend) imaginable:
[…]
@GetMapping("basic")
@ResponseBody
public void basic2() {
System.out.println("basic get invoked");
}
[…]
I’m trying to create a flutter mobile app client for this.I can invoke it via curl and I try to invoke it like this:
Future<void> _fetchData(String email) async {
http.Response response = await
http.get(Uri.parse("http://localhost:8080/basic"));
print(response.statusCode);
}
Internet access is enabled in android manifest.
I always get the same issue.
‘Unhandled Exception: Connection failed’
Do you have any idea why am I getting this?
Tried with/without port. With/with http protocol. I see in the documentation this is the way, but it doesn’t want to work really.
2
Answers
I have found the solution. So I added a try-catch block and looked into the exception and I saw it's a
and I figured I'm missing the permission in DebugProfile.entitlements. I added
Also this article is about my issue: SocketException: Connection failed (OS Error: Operation not permitted, errno = 1) with flutter app on macOS
Thank you guys for the help!
I suppose that your Spring backend runs on your host operating system, not on the Android emulated device itself. You need to use
10.0.2.2
as your "new"localhost
.How can I access my localhost from my Android device?
This doesn’t apply on the iOS simulator though.