NetworkOutputStream constructor

NetworkOutputStream(
  1. HttpClientRequest _request
)

An OutputStream implementation that writes bytes to a Dart HttpClientRequest.

This stream is used to send body content to a server over HTTP.

Use case:

This is typically used by a higher-level UrlConnection abstraction to manage writing request bodies before connecting the request.

Example:

final request = await HttpClient().postUrl(Uri.parse('https://example.com'));
final stream = NetworkOutputStream(request);

await stream.write([72, 101, 108, 108, 111]); // writes "Hello"
await stream.flush(); // ensures data is sent to the request buffer
await stream.close(); // closes the stream (but not the request itself)

// The actual HTTP request is sent by calling:
final response = await request.close();

⚠️ Do not call _request.close() in this stream. That should be done externally.

Creates a new instance that wraps the provided HttpClientRequest.

Implementation

NetworkOutputStream(this._request);