title: Unable to make calls to Localhost using Flutter, random port being assigned to HTTP GET call
body: <p>I'm attempting to build a Flutter app where I'm required to make an HTTP call using the <a href="https://github.com/dart-lang/http" rel="noreferrer">dart http library</a>. So here's a snipped of the fu I use to make the call,</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'dart:async';
  import 'dart:convert';
  import 'dart:io';
  import 'package:http/http.dart' as http;
  
  Future&lt;List&gt; getData() async {
      List data = new List();
      var httpClient = new HttpClient();
      var request = await httpClient.get("localhost", 5000, '/search?query=hello');
      var response = await request.close();
      if (response.statusCode == HttpStatus.OK) {
        var jsonString = await response.transform(utf8.decoder).join();
        data = json.decode(jsonString);
        print(data);
        return data;
      } else {
        return data;
      }
    }
  </code></pre>
  
  <p>now on calling <code>getData()</code> from my code, here's the error I get</p>
  
  <pre><code>E/flutter (30949): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
  E/flutter (30949): SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 46999
  E/flutter (30949): #0      _HomePageState.getData (file:///home/bholagabbar/AndroidStudioProjects/fnd_modile_client/lib/main.dart:75:19)
  E/flutter (30949): &lt;asynchronous suspension&gt;
  E/flutter (30949): #1      _HomePageState.build.&lt;anonymous closure&gt; (file:///home/bholagabbar/AndroidStudioProjects/fnd_modile_client/lib/main.dart:56:15)
  E/flutter (30949): #2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:478:14)
  E/flutter (30949): #3      _InkResponseState.build.&lt;anonymous closure&gt; (package:flutter/src/material/ink_well.dart:530:30)
  E/flutter (30949): #4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
  E/flutter (30949): #5      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
  E/flutter (30949): #6      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
  E/flutter (30949): #7      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
  E/flutter (30949): #8      PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
  E/flutter (30949): #9      PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
  E/flutter (30949): #10     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
  E/flutter (30949): #11     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
  E/flutter (30949): #12     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
  E/flutter (30949): #13     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
  E/flutter (30949): #14     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
  E/flutter (30949): #15     _invoke1 (dart:ui/hooks.dart:134:13)
  E/flutter (30949): #16     _dispatchPointerDataPacket (dart:ui/hooks.dart:91:5)
  </code></pre>
  
  <p>My API is up and running correctly, As you can see in the error logs, the request just doesn't seem to be going through. What exactly is the issue here? </p>
  
  <p>For the record, I have tried every permutation of <code>get</code>, <code>getUrl</code> and even tried replacing <code>localhost</code> and <code>127.0.0.1</code> with <code>10.0.2.2</code> as mentioned in <a href="https://stackoverflow.com/questions/47372568/how-to-point-to-localhost8000-with-the-dart-http-package-in-flutter?rq=1">How to point to localhost:8000 with the Dart http package in Flutter?</a> . I am testing this on my phone directly (One Plus 3)</p>