title: How to make http get request from flutter app to the localhost?
body: <p>Basically I am making a request GET from a flutter app to my localhost, I have my own Web API in visual studio, and whenever I make the request it gives me Bas Request[400]. So when I make this request it gives my bad request and that's also the case if I make the request using my IP address because I am using an actual android phone to run flutter and I can't request using 'localhost' So I wrote the IP Address of my machine. and even in postman the same.</p>
  <p>my fluuter app:</p>
  <pre><code>import 'dart:io';
  import 'package:dio/adapter.dart';
  import 'package:flutter/material.dart';
  import 'package:dio/dio.dart';
  
  
  class Project {
    final String Id;
    final String Name;
    final double Amount;
  
  
    Project({this.Id, this.Name, this.Amount});
  
    factory Project.fromJson(Map&lt;String, dynamic&gt; json) {
      return Project(
        Id: json['Id'],
        Name: json['Name'],
        Amount: json['Amount'],
      );
    }
  }
  
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatefulWidget {
    MyApp({Key key}) : super(key: key);
  
    @override
    _MyAppState createState() =&gt; _MyAppState();
  }
  
  class _MyAppState extends State&lt;MyApp&gt; {
  
    List&lt;Project&gt; projects = new List&lt;Project&gt;();
    String url = &quot;https://192.168.100.5:44391&quot;;
  
    void fetsh() async
    {
      Dio dio = new Dio();
      (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
          (HttpClient client) {
        client.badCertificateCallback =
            (X509Certificate cert, String host, int port) =&gt; true;
        return client;
      };
      try
      {
        var respond = await dio.get(&quot;$url/api/Project&quot;);
        print(respond.statusCode);
        print(respond.data);
        var respondData = respond.data as List;
        setState(() {
          projects = respondData.map((e) =&gt; Project.fromJson(e)).toList();
        });
  
      }
      catch(e) {
        print(&quot;error&quot;);
        print(e);
      }
  
    }
  
  
  
    @override
    void initState() {
      super.initState();
      fetsh();
    }
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Fetch Data Example',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('Fetch Data Example'),
          ),
          body: ListView.builder(
              itemCount: this.projects.length,
              itemBuilder: (BuildContext context, int index) {
                return new Text(this.projects[index].Name);
              }
          )
        ),
      );
    }
  }
  </code></pre>
  <p>and the server-side:</p>
  <pre><code>using demo.Models;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Net.Http;
  using System.Web.Http;
  
  namespace demo.Controllers
  {
      public class ProjectController : ApiController
      {
          List&lt;Project&gt; mylist = new List&lt;Project&gt;();
          public ProjectController()
          {
              mylist.Add(new Project { Id = 1, Name = &quot;Project 1&quot;, Amount = 150 });
              mylist.Add(new Project { Id = 2, Name = &quot;Project 2&quot;, Amount = 150 });
              mylist.Add(new Project { Id = 3, Name = &quot;Project 3&quot;, Amount = 150 });
  
          }
          // GET: api/Project
          public List&lt;Project&gt; Get()
          {
              return mylist;
          }
  
          [Route(&quot;api/Project/GetProjectNames&quot;)]
          [HttpGet]
          public List&lt;string&gt; GetProjectNames() 
          {
              List&lt;string&gt; output = new List&lt;string&gt;();
              foreach (var item in mylist)
              {
                  output.Add(item.Name);
              }
              return output;
          }
  
          // GET: api/Project/5
          public Project Get(int id)
          {
              return mylist.Where(x=&gt;x.Id == id).FirstOrDefault();
          }
  
          // POST: api/Project
          public void Post([FromBody]string value)
          {
          }
  
          // PUT: api/Project/5
          public void Put(int id, [FromBody]string value)
          {
          }
  
          // DELETE: api/Project/5
          public void Delete(int id)
          {
          }
      }
  }
  </code></pre>