openStream method

Future<InputStream> openStream()

Opens a connection to this Url and returns an InputStream to read from it.

This is a convenience method that:

  1. Creates a UrlConnection
  2. Connects to the URL
  3. Returns the input stream for the response body

Throws a NetworkException on failure.

Example

final stream = await Url('https://example.com').openStream();

Implementation

Future<InputStream> openStream() async {
  final connection = openConnection();
  await connection.connect();
  return connection.getInputStream();
}