v1.0.16 utf8 decoding
This commit is contained in:
parent
f2f70a6db9
commit
27299ed266
4
.gitignore
vendored
4
.gitignore
vendored
@ -28,5 +28,5 @@ migrate_working_dir/
|
||||
.packages
|
||||
build/
|
||||
.dart_tool/
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
/.flutter-plugins
|
||||
/.flutter-plugins-dependencies
|
@ -1,5 +1,8 @@
|
||||
Workout Test and Diet 4 You Common Util Functions
|
||||
|
||||
Version 1.0.16
|
||||
Webapi utf8 decode
|
||||
|
||||
Version 1.0.15
|
||||
AppText and translations
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: workouttest_util
|
||||
description: Workout Test app and web functions.
|
||||
version: 1.0.15
|
||||
version: 1.0.16
|
||||
|
||||
environment:
|
||||
sdk: ">=2.18.6 <3.0.0"
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:workouttest_util/model/cache.dart';
|
||||
import 'package:workouttest_util/service/api.dart';
|
||||
@ -9,7 +11,6 @@ main() {
|
||||
});
|
||||
|
||||
group('api', () {
|
||||
|
||||
test('connect api auth successfully', () async {
|
||||
var api = APIClient();
|
||||
var responseJson = await api.authenticateUser("bosi", "andio2009");
|
||||
@ -27,5 +28,20 @@ main() {
|
||||
final body = await api.get("app_package", "");
|
||||
print(body);
|
||||
});
|
||||
|
||||
test('test customer conversation in utf8', () async {
|
||||
var api = APIWebClient();
|
||||
var responseJson = await api.authenticateUser("bosi", "andio2009");
|
||||
print(responseJson);
|
||||
Cache().authToken = responseJson['token'];
|
||||
final body = await api.get("customer_conversation/72", "");
|
||||
|
||||
List<int> bytes3 = base64.decode(body);
|
||||
String decodedString = utf8.decode(bytes3);
|
||||
print(decodedString);
|
||||
|
||||
final body2 = await api.get("meal/21", "");
|
||||
print(body2);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user