title: How to connect to Localhost?
body: <p>I'm here new, I'm learning flutter and I need login with this:<br />
  POST http://localhost:3000/api/users/session</p>
  <p>But I still can't login :( I'm waiting 5 minutes and still there is a loading screen with no effects.</p>
  <p>I have try</p>
  <p>So I have have made a this api_service with this tutorial made <a href="https://www.youtube.com/watch?v=_Kw4BfNX1-4" rel="nofollow noreferrer">https://www.youtube.com/watch?v=_Kw4BfNX1-4</a></p>
  <p>here is my api_service.dart</p>
  <pre><code>import 'package:http/http.dart' as http;
  import 'dart:convert';
  import '../model/login_model.dart';
  
  class APIService {
  Future&lt;LoginResponseModel&gt; 
  login(LoginRequestModel requestModel) async {
  String url = &quot;http://localhost:3000/api/users/session&quot;;
  
  final response = await http.post(url, body: requestModel.toJson());
  if (response.statusCode == 200 || response.statusCode == 400) {
    return LoginResponseModel.fromJson(
      json.decode(response.body),
    );
  } else {
    throw Exception('Failed to load data!');
  }
  }
  }
  </code></pre>
  <p>Here is debug console:</p>
  <blockquote>
  <p>E/flutter (10967): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)]
  Unhandled Exception: SocketException: OS Error: Connection refused,
  errno = 111, address = localhost, port = 58856 E/flutter (10967):</p>
  <p>I'm try with this page:
  <a href="https://medium.com/@podcoder/connecting-flutter-application-to-localhost-a1022df63130" rel="nofollow noreferrer">https://medium.com/@podcoder/connecting-flutter-application-to-localhost-a1022df63130</a></p>
  <p>I change String url = &quot;http://localhost:3000/api/users/session&quot;; to
  String url = &quot;http://10.0.2.2:3000/api/users/session&quot;;</p>
  <p>in my debug console i have completely different messages, but stilll
  don't work :(</p>
  <p>E/flutter (10967):</p>
  <p>[ERROR:flutter/lib/ui/ui_dart_state.cc(186)]</p>
  <p>Unhandled Exception: Bad state: Insecure HTTP is not allowed by
  platform: <a href="http://10.0.2.2:3000/api/users/session" rel="nofollow noreferrer">http://10.0.2.2:3000/api/users/session</a></p>
  <p>E/flutter (10967): #0      _HttpClient._openUrl
  (dart:_http/http_impl.dart:2434:7)</p>
  <p>E/flutter (10967): #1      _HttpClient.openUrl
  (dart:_http/http_impl.dart:2341:7)</p>
  <p>E/flutter (10967): #2      IOClient.send
  package:http/src/io_client.dart:31</p>
  <p>(...) to #28 and the last ist E/flutter (10967):</p>
  </blockquote>