title: How to solve flutter web CORS error on github codespaces?
body: <p>I'm beginner on Flutter web with GitHub Codespaces.</p>
  <p>an error expected to be a CORS error occurred while calling http GET API.</p>
  <p>i have to work remotely using codespaces, and Terminal environment is Ubuntu 20.04.4 LTS.</p>
  <p>chrome is not installed there, so i open the port in code spaces and connect to it through a browser.</p>
  <p>please hope you figure it out how can i receive response from my request.</p>
  <p>THANKS!!</p>
  <hr />
  <h2>Code</h2>
  <pre class="lang-dart prettyprint-override"><code>import 'package:flutter/material.dart';
  import 'package:get/get.dart';
  import 'package:http/http.dart' as http;
  
  class TickerController extends GetxController {
    RxString text = 'Idle'.obs;
  
    getTicker() async {
      text('Start');
      var url = Uri.parse('https://api.bithumb.com/public/ticker/ETH_BTC');
      var response = await http.get(url);
      text(response.body);
    }
  }
  
  class HomePage extends StatelessWidget {
    final TickerController controller;
  
    HomePage({Key? key})
        : controller = TickerController(),
          super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Column(
          children: [
            ElevatedButton(
              child: const Text('Run'),
              onPressed: controller.getTicker,
            ),
            Obx(() {
              return Text(controller.text.value);
            }),
          ],
        ),
      );
    }
  }
  </code></pre>
  <p><code>flutter run -d web-server --web-hostname=0.0.0.0</code></p>
  <hr />
  <h2>TRY</h2>
  <p>Set codespaces port visibility to &quot;public&quot;</p>
  <p>Add request headers</p>
  <pre class="lang-dart prettyprint-override"><code>var response = await http.get(url, headers: {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Credentials': 'true',
    'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Amz-Date, Authorization, X-Api-Key, X-Amz-Security-Token, locale',
    'Access-Control-Allow-Methods': 'GET, POST',
  }); 
  </code></pre>
  <p>Run with python http.server</p>
  <pre class="lang-py prettyprint-override"><code>from http.server import HTTPServer, SimpleHTTPRequestHandler
  
  class CORSRequestHandler(SimpleHTTPRequestHandler):
      def end_headers(self):
          self.send_header('Access-Control-Allow-Origin', '*')
          self.send_header('Access-Control-Allow-Methods', 'GET, POST')
          self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
          return super(CORSRequestHandler, self).end_headers()
  
  server = HTTPServer(('localhost', 8000), CORSRequestHandler)
  server.serve_forever()
  </code></pre>
  <p>and build flutter project <code>flutter build web</code>,
  run python server <code>../build/web$</code> <code>python server.py</code></p>
  <hr />
  <h2>ERROR</h2>
  <p><a href="https://i.stack.imgur.com/yVfSe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yVfSe.png" alt="Browser console error image" /></a></p>