readBytes method

  1. @override
Future<Uint8List> readBytes(
  1. Uri url, {
  2. Map<String, String>? headers,
})

Sends an HTTP GET request with the given headers to the given URL and returns a Future that completes to the body of the response as a list of bytes.

The Future will emit a ClientException if the response doesn't have a success status code.

For more fine-grained control over the request and response, use send or get instead.

Implementation

@override
Future<Uint8List> readBytes(
  Uri url, {
  Map<String, String>? headers,
}) async {
  final req = http.Request('GET', url);
  req.headers.addAll(headers ?? {});

  final res = await send(req);
  return res.stream.toBytes();
}