GithubHelp home page GithubHelp logo

XMLHttpRequest error about http HOT 10 CLOSED

dart-lang avatar dart-lang commented on August 28, 2024
XMLHttpRequest error

from http.

Comments (10)

rodydavis avatar rodydavis commented on August 28, 2024 2

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.

from http.

syleishere avatar syleishere commented on August 28, 2024 2

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

from http.

nex3 avatar nex3 commented on August 28, 2024 1

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

from http.

david-onehub-dev avatar david-onehub-dev commented on August 28, 2024

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.

from http.

nex3 avatar nex3 commented on August 28, 2024

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

from http.

karelric avatar karelric commented on August 28, 2024

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?

from http.

 avatar commented on August 28, 2024

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.

from http.

rodydavis avatar rodydavis commented on August 28, 2024

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

from http.

 avatar commented on August 28, 2024

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)

from http.

sh0umik avatar sh0umik commented on August 28, 2024

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

from http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.