|
|
@ -56,12 +56,21 @@ Future _apiRequest(String method, String path, dynamic data,
|
|
|
|
var client = HttpClient();
|
|
|
|
var client = HttpClient();
|
|
|
|
HttpClientRequest r;
|
|
|
|
HttpClientRequest r;
|
|
|
|
if (method == 'POST') {
|
|
|
|
if (method == 'POST') {
|
|
|
|
r = await client.postUrl(Uri.parse('https://' + serverHost + path));
|
|
|
|
r = await client.postUrl(Uri.parse(serverHost + path));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
r = await client.getUrl(Uri.parse('https://' + serverHost + path));
|
|
|
|
r = await client.getUrl(Uri.parse(serverHost + path));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var strData = '';
|
|
|
|
|
|
|
|
if (data != null) {
|
|
|
|
|
|
|
|
strData = jsonEncode(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (method == 'POST') {
|
|
|
|
|
|
|
|
r.headers.set('Content-Type', 'application/json; charset=utf-8');
|
|
|
|
|
|
|
|
r.headers.set('Content-Length', utf8.encode(strData).length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
r.headers.set('Content-Type', 'application/json; charset=utf-8');
|
|
|
|
|
|
|
|
if (tokens != null) {
|
|
|
|
if (tokens != null) {
|
|
|
|
r.headers.set('Authorization', tokens.accessToken);
|
|
|
|
r.headers.set('Authorization', tokens.accessToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -70,11 +79,9 @@ Future _apiRequest(String method, String path, dynamic data,
|
|
|
|
r.headers.set(k, v);
|
|
|
|
r.headers.set(k, v);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var strData = '';
|
|
|
|
|
|
|
|
if (data != null) {
|
|
|
|
|
|
|
|
strData = jsonEncode(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
r.write(strData);
|
|
|
|
r.write(strData);
|
|
|
|
|
|
|
|
|
|
|
|
var rp = await r.close();
|
|
|
|
var rp = await r.close();
|
|
|
|
var body = await rp.transform(utf8.decoder).join();
|
|
|
|
var body = await rp.transform(utf8.decoder).join();
|
|
|
|
print('${rp.statusCode} - $path');
|
|
|
|
print('${rp.statusCode} - $path');
|
|
|
@ -147,12 +154,19 @@ Future _apiRequest(String method, String path, dynamic data,
|
|
|
|
var client = HttpClient();
|
|
|
|
var client = HttpClient();
|
|
|
|
HttpClientRequest r;
|
|
|
|
HttpClientRequest r;
|
|
|
|
if (method == 'POST') {
|
|
|
|
if (method == 'POST') {
|
|
|
|
r = await client.postUrl(Uri.parse('https://' + serverHost + path));
|
|
|
|
r = await client.postUrl(Uri.parse(serverHost + path));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
r = await client.getUrl(Uri.parse('https://' + serverHost + path));
|
|
|
|
r = await client.getUrl(Uri.parse(serverHost + path));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
r.headers.set('Content-Type', 'application/json; charset=utf-8');
|
|
|
|
var strData = '';
|
|
|
|
|
|
|
|
if (data != null) {
|
|
|
|
|
|
|
|
strData = jsonEncode(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (method == 'POST') {
|
|
|
|
|
|
|
|
r.headers.set('Content-Type', 'application/json; charset=utf-8');
|
|
|
|
|
|
|
|
r.headers.set('Content-Length', utf8.encode(strData).length);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (tokens != null) {
|
|
|
|
if (tokens != null) {
|
|
|
|
r.headers.set('Authorization', tokens.accessToken);
|
|
|
|
r.headers.set('Authorization', tokens.accessToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -161,10 +175,7 @@ Future _apiRequest(String method, String path, dynamic data,
|
|
|
|
r.headers.set(k, v);
|
|
|
|
r.headers.set(k, v);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var strData = '';
|
|
|
|
|
|
|
|
if (data != null) {
|
|
|
|
|
|
|
|
strData = jsonEncode(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
r.write(strData);
|
|
|
|
r.write(strData);
|
|
|
|
var rp = await r.close();
|
|
|
|
var rp = await r.close();
|
|
|
|
var body = await rp.transform(utf8.decoder).join();
|
|
|
|
var body = await rp.transform(utf8.decoder).join();
|
|
|
|