Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web]: Http requests throw XMLHttpRequest error #57421

Closed
harshraj6982 opened this issue May 17, 2020 · 23 comments
Closed

[web]: Http requests throw XMLHttpRequest error #57421

harshraj6982 opened this issue May 17, 2020 · 23 comments
Labels
in triage Presently being triaged by the triage team

Comments

@harshraj6982
Copy link

harshraj6982 commented May 17, 2020

Error: XMLHttpRequest error.
    dart:sdk_internal 118163:30                           get current
packages/http/src/browser_client.dart.lib.js 212:124  <fn>
dart:sdk_internal 35540:58                            runUnary
dart:sdk_internal 30956:29                            handleValue
dart:sdk_internal 31466:49                            handleValueCallback
dart:sdk_internal 31498:17                            _propagateToListeners
dart:sdk_internal 31348:25                            [_complete]
dart:sdk_internal 35874:24                            _cancelAndValue
dart:sdk_internal 18161:17                            <fn>
dart:sdk_internal 4978:16                             _checkAndCall
dart:sdk_internal 4983:17                             dcall
dart:sdk_internal 99467:93                            <fn>
    at Object.createErrorWithStack (http://localhost:49173/dart_sdk.js:4786:12)
    at Object._rethrow (http://localhost:49173/dart_sdk.js:35900:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:49173/dart_sdk.js:35896:13)
    at Object._microtaskLoop (http://localhost:49173/dart_sdk.js:35756:13)
    at _startMicrotaskLoop (http://localhost:49173/dart_sdk.js:35762:13)

Facing this issue on flutter web only, works fine on flutter mobile.

@pingbird
Copy link
Member

Check the debug console in your browser for more details on why the http request failed

@iapicca
Copy link
Contributor

iapicca commented May 18, 2020

Hi @PixelToast
can you please provide your flutter doctor -v ,
your flutter run --verbose,
your pubspec.yaml
and a reproducible minimal code sample.
Thank you

@iapicca iapicca added in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels May 18, 2020
@harshraj6982
Copy link
Author

I solved the issue

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 20, 2020
@bimsina
Copy link

bimsina commented May 27, 2020

@harshraj6982 please provide info on how the issue was solved before closing the issue.

@iapicca
Copy link
Contributor

iapicca commented May 27, 2020

Could everyone who still has this problem please file a new issue with the exact description of what happens, logs and the output of flutter doctor -v.
All system setups can be slightly different, so it's always better to open new issues and reference related issues.

@bimsina
Copy link

bimsina commented May 27, 2020

Here is the code that I'm trying to run :

Map<String, dynamic> body = {
'client_secret': _clientSecret,
'source': "print'Hello World!'",
'lang': 'PYTHON',
};
http
.post('https://api.hackerearth.com/v3/code/run',
body: jsonEncode(body))
.then((value) => print(value))
.catchError((error) => print(error));

Here is the error :
Error: XMLHttpRequest error. dart:sdk_internal 123890:30 get current packages/http/src/browser_client.dart.lib.js 212:124 <fn> dart:sdk_internal 36953:58 runUnary dart:sdk_internal 32045:29 handleValue dart:sdk_internal 32592:49 handleValueCallback dart:sdk_internal 32630:17 _propagateToListeners dart:sdk_internal 32464:25 [_complete] dart:sdk_internal 37363:24 _cancelAndValue dart:sdk_internal 18428:17 <fn>

Here's the o/p to flutter doctor -v
`[✓] Flutter (Channel master, 1.19.0-2.0.pre.143, on Microsoft Windows [Version 10.0.19041.264], locale en-US)
• Flutter version 1.19.0-2.0.pre.143 at C:\src\flutter
• Framework revision 9d58a87 (4 days ago), 2020-05-22 22:37:01 -0700
• Engine revision 9ce1e5c
• Dart version 2.9.0 (build 2.9.0-10.0.dev 7706afbcf5)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\timsi\AppData\Local\Android\sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.

[✓] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[✗] Visual Studio - develop for Windows
✗ Visual Studio not installed; this is necessary for Windows development.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including the following components:
MSBuild
MSVC v142 - VS 2019 C++ x64/x86 build tools
- If there are multiple build tool versions available, install the latest
Windows 10 SDK (10.0.17763.0)

[✓] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 45.0.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[✓] VS Code (version 1.45.1)
• VS Code at C:\Users\timsi\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.10.2

[✓] Connected device (3 available)
• Windows • Windows • windows-x64 • Microsoft Windows [Version 10.0.19041.264]
• Web Server • web-server • web-javascript • Flutter Tools
• Chrome • chrome • web-javascript • Google Chrome 83.0.4103.61`

@harshraj6982
Copy link
Author

Just enable cors it will not throw this kind of error. I just forget to enable cors in my backend.

@Liam-Kim
Copy link

Liam-Kim commented Jun 5, 2020

hello I have same issue with flutter web. Could you let me know the solution in detail~?

@harshraj6982
Copy link
Author

harshraj6982 commented Jun 7, 2020

hello I have same issue with flutter web. Could you let me know the solution in detail~?

Which backend you are using in your project?
This problem occurs due to backend you are using, there is nothing wrong with flutter web.

@Liam-Kim
Copy link

hello I have same issue with flutter web. Could you let me know the solution in detail~?

Which backend you are using in your project?
This problem occurs due to backend you are using, there is nothing wrong with flutter web.

Using firebase now. How could i fix it? Do you Let me know any tip?

@harshraj6982
Copy link
Author

harshraj6982 commented Jun 11, 2020

Then you should contact firebase support.
Also you can message me on Instagram I'll be happy be help you
My Instagram Id is harshraj6982

@mhunchojack
Copy link

I have cors enabled in django but still getting same error, please help

@abumasum
Copy link

Just enable cors it will not throw this kind of error. I just forget to enable cors in my backend.

I have got the same problem..can you show me how to enable cors?

@suragch
Copy link
Contributor

suragch commented Jan 23, 2021

@michaeldwu
Copy link

michaeldwu commented Feb 4, 2021

@suragch I'm experiencing the same problem as well. I've taken a look at the link but it doesn't seem to be helpful for non-AWS backends. I'm currently using Google Cloud Platform's Compute Engine and Firebase on the server side and can't figure out how to enable CORS like @abumasum too. Would really appreciate any advice or help you can give. Thanks!

@mracipayam
Copy link

mracipayam commented Apr 1, 2021

I am getting the same error with php api so i add the php code these lines ;

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");

There is no more error.It is enables CORS. I don't know what that is but i am gonna read the manuel.

@SittiphanSittisak
Copy link

SittiphanSittisak commented Apr 5, 2021

I am getting the same error with php api so i add the php code these lines ;

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");

There is no more error.It is enables CORS. I don't know what that is but I am gonna read the manual.

#Fixed Thank you so much. Did you read the manual? I suspect it too.
I only add header('Access-Control-Allow-Origin: *');. It still works.

@SittiphanSittisak
Copy link

SittiphanSittisak commented Apr 5, 2021

It's simple for using API. Browsers HTTP is usually reserved access data from other domains. We call this CORS. So we can't use API without permission from this domain. If you are the host of this domain, you can set by following this https://enable-cors.org/server.html (It have many kind of server API). I hope it can help you all. If I miss understand, help me for improve my self. : )

@mracipayam
Copy link

It's simple for using API. Browsers HTTP is usually reserved access data from other domains. We call this CORS. So we can't use API without permission from this domain. If you are the host of this domain, you can set by following this https://enable-cors.org/server.html. I hope it can help you all.

Oh thank you! Very useful link.

@exeptionerror

This comment was marked as spam.

@mracipayam
Copy link

mracipayam commented Jun 28, 2021 via email

@glennmichaelmejias
Copy link

glennmichaelmejias commented Jul 15, 2021

edit both files

etc/apache2/apache2.conf
etc/apache2/httpd.conf

and add this to the end

Header set Access-Control-Allow-Origin "*"

then restart apache on terminal

service apache2 restart

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in triage Presently being triaged by the triage team
Projects
None yet
Development

No branches or pull requests