I have seen numerous posts on the flutter github as well as here regarding my issue however it still persists. I have an ASP.NET API that is being hosted on port 5001 that returns a JSON object. I have tried changing the URL to point to 10.0.2.2:5001 in place of localhost, adding 10.0.2.2 with the port number as a proxy on the emulator, downgrading the emualtor to Pie. None of these have worked for me. Here is the troublesome section of code in question:
Future<Foo> fetchJson() async {
var response = await client.get(
"http://10.0.2.2:5001/api/SampleApp/FetchObject",
headers: {"Accept": "application/json", "Content": "application/json"});
var something = Foo.fromJson(jsonDecode(response.body));
return something;
}
Exception has occurred.
ClientException (Connection closed before full header was received)