getInputStream method

InputStream getInputStream()

Returns an InputStream that reads the response body of this connection.

Throws a NetworkException if connect has not yet been called or the response has not been received.

Example

final stream = connection.getInputStream();
int byte;
while ((byte = await stream.readByte()) != -1) {
  // Process each byte
}

Implementation

InputStream getInputStream() {
  if (!_connected || _response == null) {
    throw NetworkException('Connection not established or response not received.');
  }
  return NetworkInputStream(_response!);
}