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

XMLHttpRequest error #67

Closed
floitschG opened this issue Mar 15, 2017 · 10 comments
Closed

XMLHttpRequest error #67

floitschG opened this issue Mar 15, 2017 · 10 comments
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@floitschG
Copy link
Contributor

From @SadovovAlex on March 14, 2017 12:7

if response this format or other json:
{"listFias":[],"status":"NotFound"}

i recieved error:
XMLHttpRequest cannot load http://0001qwerty02:8888

  var client = new BrowserClient();
  var url = '/whatsit/create';
  var response =
      await client.post(url, body: {'name': 'doodle', 'color': 'blue'});
  print('Response status: ${response.statusCode}');
  print('Response body: ${response.body}');

Copied from original issue: dart-lang/sdk#29068

@nex3
Copy link
Member

nex3 commented May 15, 2017

Have you tried making the request with the plain HttpRequest class? If that reproduces the error, it's not related to the http package.

@nex3 nex3 added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) needs info labels May 15, 2017
@david-onehub-dev
Copy link

we ran into this XMLHttpRequest error when oauth token is expired. browser client is unable to capture http request 401 and return response. Instead, ClientException is thrown from http pacakge.

@nex3
Copy link
Member

nex3 commented Mar 22, 2018

@david-onehub-dev Same question: what happens when you make the request with a plain HttpRequest? And what exception is being thrown?

@karelric
Copy link

Hi, I'm still having this problem only when I use cross domain request.

http.get('https://api.domain.com/non-exists-path');

This will throw a XMLHttpRequest error instead of return a Response object with status code 404.

What I can do?

@rodydavis
Copy link

rodydavis commented Jun 18, 2019

This happens when I post to a URL.

    var client = new http.Client();

    final _body = {
      "grant_type": "password",
      "username": _username.text,
      "password": _password.text,
    };

    await updateLog(_body.toString(), duration: Duration(seconds: 2));

    try {
      final _data = await client.post(url, body: _body, headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      });
      await updateLog(_data.toString(), duration: Duration(seconds: 2));
    } catch (e) {
      await updateLog('Post Error..', duration: Duration(seconds: 1));
      await updateLog(e.toString(), duration: Duration(seconds: 1));
    }

returns XML.HttpRequest error.

@ghost
Copy link

ghost commented Jun 19, 2019

This looks like a known limitation in the BrowserClient (seemingly based on a known limitation in XHR):

      // Unfortunately, the underlying XMLHttpRequest API doesn't expose any
      // specific information about the error itself.
      completer.completeError(
          ClientException("XMLHttpRequest error.", request.url),
          StackTrace.current);

XHR's onerror is fired for network-level errors (i.e. where there is no HTTP response code).
This might seem contrary to what you're seeing when the network tab shows 404, but for CORS error this makes sense since the browser does see the 404, but then decides to block the response from reaching the application based on the missing CORS headers.
From the application's PoV there was no 404, only network error. Hence there is only the generic "XMLHttpRequest error" to fall back on.

From a dev's perspective this is a generic network error caused by CORS, which needs to be fixed on the server side.

As for this issue I'd say this is all WAI in the context of the limitations imposed by XHR and CORS.

@rodydavis
Copy link

Gotcha. Yeah I have building Flutter apps for desktop and mobile and it’s just now when running the apps in the browser where it started breaking. Specifically logging in. So I am use firebase now as a proxy server

@ghost
Copy link

ghost commented Jun 21, 2019

I'm closing this issue since the original issue hasn't been updated since 2017 and the pings since then seem to be explained by #67 (comment)

@ghost ghost closed this as completed Jun 21, 2019
@sh0umik
Copy link

sh0umik commented Jan 10, 2020

I need to test this in Browser ? Any Solution without hosting it in firebase ?

@syleishere
Copy link

Response code comes back null when using flutter web(browser), this is why this is happening.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants