I'm following the Flutter Networking/HTTP tutorial to do a GET request to a server running on my localhost:8000. Visiting my localhost via my browser works fine. My code looks like this:
var url = 'http://localhost:8000';
Future<String> getUnits(String category) async {
var response = await httpClient.get('$url/$category');
return response.body;
}
https://example.com
https://localhost:8000
https://localhost
E/flutter ( 4879): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 4879): SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 47060
E/flutter ( 4879): #0 IOClient.send (package:http/src/io_client.dart:30:23)
Short answer: You can pass an Uri instead of a string as parameter
var client = createHttpClient();
client.get(new Uri.http("locahost:8000", "/category"));