Back

xmlHttpRequest Error Flutter HTTP Package

  • 1
  • Flutter
plushteddy
22 Feb, 2024, 21:41

Hello, if I run a http request on the web I alway get a xmlhttprequest error, does anybody know how to fix that issue?

code:

TypeScript
Future<bool> checkName(String name) async {
  const apiUrl = 'https://...';

  try {
    final response = await http.get(Uri.parse(apiUrl));

    if (response.statusCode == 200) {
      final Map<String, dynamic> data = json.decode(response.body);

      // Überprüfe, ob 'names' in den Daten vorhanden ist
      if (data.containsKey('names')) {
        return data['names'].contains(name);
      } else {
        throw Exception('Ungültiges Format der API-Antwort: \'names\' nicht gefunden.');
      }
    } else {
      throw Exception('Fehler bei der API-Anfrage: ${response.statusCode}');
    }
  } catch (e) {
    print('Fehler: $e');
    return false;
  }
}```

I know that I am here on the appwrite discord, but I could find help on the internet and other servers.
TL;DR
Developers are experiencing an xmlhttprequest error in Flutter's HTTP package. There is a suggestion to use the SDK for Flutter to handle sessions. One developer is facing an issue with a http request on the web. A code snippet for a function called 'checkName' is provided, where the error occurs. Solution: The developer can try using Flutter's SDK for better session handling.
D5
22 Feb, 2024, 21:59

You're doing requests with the API?

D5
22 Feb, 2024, 22:00

I suggest using the SDK for flutter since it will handle sessions, etc.

Anyways, what are the requests that you're performing?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more