title: XMLHttpRequest error while using http post flutter web
body: <p>I am facing this error <code>XMLHttpRequest error.</code> while making an HTTP post call to my API-AWS API Gateway. My current Flow is Flutter web -&gt; API gateway -&gt; lambda -&gt; rds.</p>
  <p>I know there are already a couple of question-related to this <a href="https://stackoverflow.com/questions/60191683/xmlhttprequest-error-in-flutter-web-enabling-cors-aws-api-gateway">like</a> but as suggested in one of the answers to add some headers in response to lambda. but it doesn't work for me.</p>
  <p>After doing some research I found out that the problem is regarding to CORS. now disabling cors in chrome is a temporary fix and suggested in this <a href="https://stackoverflow.com/questions/56139505/how-to-make-http-request-to-in-flutter-web/59552060#59552060">question</a>.</p>
  <p>some other solution that I found after researching suggested to enabled cors in my API and also in the frontend part I have added headers but none of them works.</p>
  <pre><code>fetchData() async {
      String url =
          &quot;myUrl&quot;;
      Map&lt;String, String&gt; headers = {
        &quot;Access-Control-Allow-Origin&quot;: &quot;*&quot;, // Required for CORS support to work
      };
      String json = '{&quot;emailId&quot;:&quot;emailId&quot;}';
      http.Response response =
          await http.post(Uri.parse(url), headers: headers, body: json);
      print(response.body);
      return response.body;
    }
  </code></pre>
  <p>what is the correct way of solving this problem?</p>