[Solved] IN Flutter Web getting ‘XMLHttpRequest’ error while making HTTP call

Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. flutter Web getting ‘XMLHttpRequest’ error while making HTTP call. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How Flutter Web getting ‘XMLHttpRequest’ error while making HTTP call Error Occurs ?

I am working in flutter web. I am using api to fetch data but I got error from http plugin here is my stack track.

Launching lib\main.dart on Chrome in debug mode...
Syncing files to device Chrome...
Debug service listening on ws://127.0.0.1:56619/FsXy3a4ZrZg=
Debug service listening on ws://127.0.0.1:56619/FsXy3a4ZrZg=
Error: XMLHttpRequest error.

Here is my code

Future getApiData()async {
    final response = await http.get(
        'http://my_web_url/project_pinn/list_cat.php',
        headers: {
          "Accept": "application/json",
          "Access-Control_Allow_Origin": "*"
        });

    print(response.statusCode);
    print(response.body);
  }

How to Solve Flutter Web getting ‘XMLHttpRequest’ error while making HTTP call Error?

  1. How to Solve Flutter Web getting 'XMLHttpRequest' error while making HTTP call Error?

    To Solve Flutter Web getting 'XMLHttpRequest' error while making HTTP call Error Most cases of this error just add Access-Control-Allow-Origin value in the header might resolve the issue. Just make sure to replace all Underscore by Dash.

  2. Flutter Web getting 'XMLHttpRequest' error while making HTTP call

    To Solve Flutter Web getting 'XMLHttpRequest' error while making HTTP call Error Most cases of this error just add Access-Control-Allow-Origin value in the header might resolve the issue. Just make sure to replace all Underscore by Dash.

Solution 1: add Access-Control-Allow-Origin

Most cases of this error just add Access-Control-Allow-Origin value in header might resolve the issue. Just make sure to replace all Underscore by Dash.

header("Access-Control-Allow-Origin: *");

Solution 2: Fix the typo 

  1. Fix the typo (replace underscores by dashes):
  2. header("Access-Control-Allow-Origin: *");
  3. Add the following header in your PHP API code:
  4. header("Access-Control-Allow-Headers: Access-Control-Allow-Origin, Accept");

Solution 3: Upgrade plugin version

Just Update your http plugin verion.

Summery

So, It’s All About This Error. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.

Also Check Out Below Tutorials

Leave a Comment

  Canva Pro Crack Filmora Pro Crack Spotify Premium Free Download Tradingview Premium Free