httpCall method
Implementation
Future<Uint8List> httpCall(String routerHost, String function,
Uint8List frame, int timeoutMs) async {
//print("httpCall $routerHost $function");
http.Client? client;
if (httpClients.containsKey(routerHost)) {
client = httpClients[routerHost];
} else {
HttpClient.enableTimelineLogging = false;
client = http.Client();
httpClients[routerHost] = client;
}
if (client != null) {
try {
var req = http.MultipartRequest(
'POST', Uri.parse("http://$routerHost/api/$function"));
req.fields['d'] = base64Encode(frame);
http.Response response = await http.Response.fromStream(
await client.send(req).timeout(Duration(milliseconds: timeoutMs)));
if (response.statusCode == 200) {
var resStr = base64Decode(response.body);
return resStr;
}
} catch (ex) {
print("exception $function exception: $ex");
} finally {}
}
throw "Exception: status code";
}