post static method

Future<String> post(
  1. Uri uri,
  2. Map<String, Object> headers,
  3. List<int> data
)

Implementation

static Future<String> post(
  Uri uri,
  Map<String, Object> headers,
  List<int> data,
) async {
  const timeout = Duration(seconds: 15);
  final req = await _client.postUrl(uri);
  headers.forEach((name, values) {
    req.headers.set(name, values);
  });
  req.contentLength = data.length;
  req.add(data);
  final res = await req.close().timeout(timeout);
  if (res.statusCode != HttpStatus.ok) {
    final body = await res.transform(utf8.decoder).join().timeout(timeout);
    throw Exception("request $uri error , status ${res.statusCode} $body");
  }
  final body = await res.transform(utf8.decoder).join().timeout(timeout);
  return body;
}