close

[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.

Here is my code

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

Question: How to Solve Flutter Web getting ‘XMLHttpRequest’ error while making HTTP call Error?
Answer: 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.

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

%d bloggers like this: