I’m developing a Flutter app using Android Studio and trying to make requests to my API hosted on localhost:44392
, which is a .NET Framework 4.6.1 application. When I test the app on a live system, the requests work fine. However, when I change the baseURL to 10.0.2.2
, the requests fail, and I get a CONNECTION TIMEOUT
error.
Here’s how I’m making the request:
var url = Uri.parse(CONFIG.baseURL + ApiUrl.GetReservationsForCourierEndpoint);
var userId = CONFIG.user_id.toString();
var headerJson = {
"Content-Type": 'application/json; charset=UTF-8',
"OperationUserId": userId
};
var filter = jsonEncode(<String, dynamic>{
'CourierId': CONFIG.user_id,
'ReservationDate': date.toString()
});
var response = await http.post(url, headers: headerJson, body: filter);
Map<String, dynamic> data = json.decode(utf8.decode(response.bodyBytes));
I’ve tried the following methods but none of them solved the issue:
- Adding the
android:networkSecurityConfig="@xml/network_security_config"
attribute to theandroid.manifest
file and creating anetwork_security_config.xml
file with the following content:
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
- Using
adb reverse tcp:44392 tcp:44392
command in PowerShell to forward the port. - Turning off Vulkan by adding the following lines to the
.android\advancedFeatures.ini
file:
Vulkan = off
GLDirectMem = on
- Temporarily disabling Windows Defender and adding an inbound rule to allow port 44392.
The emulator’s connection details are as follows:
IP: 10.0.2.16
** GATEWAY: 10.0.2.2 **
** DNS: 10.0.2.3**
Any help would be appreciated. Thank you!