WT 1.1.17+2 error fix utf8 in names, thick pointer
This commit is contained in:
+26
-21
@@ -42,27 +42,32 @@ class APIClient with Common, Logging {
|
||||
Future<String> post(String endPoint, String body) async {
|
||||
final url = Cache().getBaseUrl() + endPoint;
|
||||
trace(" ------------ http/post body $body - url: $url ");
|
||||
String authToken = Cache().getAuthToken();
|
||||
if (authToken.length == 0) {
|
||||
var responseJson = await this.authenticateUser(Cache.username, Cache.password);
|
||||
authToken = responseJson['token'];
|
||||
Cache().authToken = authToken;
|
||||
}
|
||||
var uri = Uri.parse(url);
|
||||
HttpClient client = new HttpClient();
|
||||
client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
|
||||
final HttpClientRequest request = await client.postUrl(uri);
|
||||
request.headers.set('Content-Type', 'application/json');
|
||||
request.headers.set('Authorization', 'Bearer $authToken');
|
||||
request.contentLength = body.length;
|
||||
request.write(body);
|
||||
HttpClientResponse result = await request.close();
|
||||
trace(" ------------post response code: " + result.statusCode.toString());
|
||||
if (result.statusCode == 200) {
|
||||
return await result.transform(utf8.decoder).join();
|
||||
} else if (result.statusCode == 404) {
|
||||
throw NotFoundException(message: "Not Found");
|
||||
} else {
|
||||
try {
|
||||
String authToken = Cache().getAuthToken();
|
||||
if (authToken.length == 0) {
|
||||
var responseJson = await this.authenticateUser(Cache.username, Cache.password);
|
||||
authToken = responseJson['token'];
|
||||
Cache().authToken = authToken;
|
||||
}
|
||||
var uri = Uri.parse(url);
|
||||
HttpClient client = new HttpClient();
|
||||
client.badCertificateCallback = ((X509Certificate cert, String host, int port) => true);
|
||||
final HttpClientRequest request = await client.postUrl(uri);
|
||||
request.headers.contentType = new ContentType("application", "json", charset: "utf-8");
|
||||
request.headers.set('Authorization', 'Bearer $authToken');
|
||||
//request.contentLength = body.length;
|
||||
request.write(body);
|
||||
HttpClientResponse result = await request.close();
|
||||
trace(" ------------post response code: " + result.statusCode.toString());
|
||||
if (result.statusCode == 200) {
|
||||
return await result.transform(utf8.decoder).join();
|
||||
} else if (result.statusCode == 404) {
|
||||
throw NotFoundException(message: "Not Found");
|
||||
} else {
|
||||
throw Exception("Network Error, please try again later");
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
print("Post Exception: $e");
|
||||
throw Exception("Network Error, please try again later");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user