I want to connect my android emulator to a node js local server running localhost:2000, I searched and found a way to do it but it does not work.
The local host name in the settings of the emulator takes localhost so I used localhost as the host name, i tried using the ip address of the laptop but it invalid proxy
import 'dart:convert';
import 'package:http/http.dart' as http;
class Http {
static String url = "http://10.0.2.2:2000/api/";
static postProduct(Map pData) async {
try {
final response = await http.post(
Uri.parse("${url}add_product"),
body: pData,
);[![enter image description here][1]][1]
if (response.statusCode == 200) {
var data = jsonDecode(response.body.toString());
print(data);
} else {
print('Failed to load data');
}
} catch (e) {
print(e.toString());
}
}
}
host name]1