v1.0.16 utf8 decoding

This commit is contained in:
Tibor Bossanyi
2023-03-19 19:14:48 +01:00
parent f2f70a6db9
commit 27299ed266
5 changed files with 34 additions and 16 deletions
+10 -11
View File
@@ -23,11 +23,8 @@ class APIWebClient with Common, Logging {
log("Base URL: $baseUrl");
var url = "${baseUrl}authenticate";
try {
final body = jsonEncode(<String, String>{
'username': email,
'password': password
});
try {
final body = jsonEncode(<String, String>{'username': email, 'password': password});
var uri = Uri.parse(url);
var result = await http.post(uri, body: body, headers: {
"Content-Type": "application/json",
@@ -38,7 +35,7 @@ class APIWebClient with Common, Logging {
log("authentication response: ${result.statusCode} with URL: $url");
throw Exception("Authentication error: ${result.statusCode}");
}
String response = result.body;
log("Authentication status: ${result.statusCode}, response: $response");
final data = jsonDecode(response);
@@ -78,7 +75,7 @@ class APIWebClient with Common, Logging {
} else {
throw Exception("Network Error, please try again later");
}
} on NotFoundException catch(e) {
} on NotFoundException catch (e) {
throw NotFoundException(message: "Not Found ${e.message}");
} on Exception catch (e) {
log("Post Exception: $e");
@@ -100,18 +97,21 @@ class APIWebClient with Common, Logging {
var uri = Uri.parse(url);
var result = await http.get(uri, headers: {
"Content-Type": "application/json",
//"Accept-Charset": 'utf-8',
"Authorization": 'Bearer $authToken',
});
log(" ------------get response code: ${result.statusCode}");
if (result.statusCode == 200) {
return result.body;
List<int> bytes = result.body.codeUnits;
String decodedString = utf8.decode(bytes);
return decodedString;
} else if (result.statusCode == 404) {
throw const NotFoundException(message: "Not Found");
} else {
throw Exception("Network Error, please try again later");
}
} on NotFoundException catch(e) {
} on NotFoundException catch (e) {
throw NotFoundException(message: "Not Found ${e.message}");
} on Exception catch (e) {
log("Post Exception: $e");
@@ -119,5 +119,4 @@ class APIWebClient with Common, Logging {
throw Exception("Network Error, please try again later");
}
}
}
}