_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_
Have you tried making the request with the plain HttpRequest class? If that reproduces the error, it's not related to the http package.
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.
@david-onehub-dev Same question: what happens when you make the request with a plain HttpRequest? And what exception is being thrown?
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?
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.
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.
Gotcha. Yeah I have building Flutter apps for desktop and mobile and it鈥檚 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
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 https://github.com/dart-lang/http/issues/67#issuecomment-503461018
I need to test this in Browser ? Any Solution without hosting it in firebase ?