HttpClientRequest class

HTTP request for a client connection.

To set up a request, set the headers using the headers property provided in this class and write the data to the body of the request. HttpClientRequest is an IOSink. Use the methods from IOSink, such as writeCharCode(), to write the body of the HTTP request. When one of the IOSink methods is used for the first time, the request header is sent. Calling any methods that change the header after it is sent throws an exception.

When writing string data through the IOSink the encoding used is determined from the "charset" parameter of the "Content-Type" header.

HttpClientRequest request = ...
request.headers.contentType
    = new ContentType("application", "json", charset: "utf-8");
request.write(...);  // Strings written will be UTF-8 encoded.

If no charset is provided the default of ISO-8859-1 (Latin 1) is be used.

HttpClientRequest request = ...
request.headers.add(HttpHeaders.contentTypeHeader, "text/plain");
request.write(...);  // Strings written will be ISO-8859-1 encoded.

An exception is thrown if you use an unsupported encoding and the write() method being used takes a string parameter.

Implemented types

Constructors

HttpClientRequest()

Properties

bufferOutputbool
read / write
Gets or sets if the HttpClientRequest should buffer output. [...]
connectionInfoHttpConnectionInfo?
read-only
Gets information about the client connection. [...]
contentLengthint
read / write
Gets and sets the content length of the request. [...]
cookiesList<Cookie>
read-only
Cookies to present to the server (in the 'cookie' header).
doneFuture<HttpClientResponse>
read-only, override
A HttpClientResponse future that will complete once the response is available. [...]
encodingEncoding
read / write, inherited
The Encoding used when writing strings. [...]
followRedirectsbool
read / write
Whether to follow redirects automatically. [...]
hashCodeint
read-only, inherited
The hash code for this object. [...]
headersHttpHeaders
read-only
Returns the client request headers. [...]
maxRedirectsint
read / write
Set this property to the maximum number of redirects to follow when followRedirects is true. If this number is exceeded an error event will be added with a RedirectException. [...]
methodString
read-only
The method of the request.
persistentConnectionbool
read / write
The requested persistent connection state. [...]
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.
uriUri
read-only
The uri of the request.

Methods

abort([Object? exception, StackTrace? stackTrace]) → void
@Since("2.10")
Aborts the client connection. [...]
add(List<int> data) → void
inherited
Adds byte data to the target consumer, ignoring encoding. [...]
addError(Object error, [StackTrace? stackTrace]) → void
inherited
Passes the error to the target consumer as an error event. [...]
addStream(Stream<List<int>> stream) → Future
inherited
Adds all elements of the given stream. [...]
close() → Future<HttpClientResponse>
override
Close the request for input. Returns the value of done.
flush() → Future
inherited
Returns a Future that completes once all buffered data is accepted by the underlying StreamConsumer. [...]
noSuchMethod(Invocation invocation) → dynamic
inherited
Invoked when a non-existent method or property is accessed. [...]
toString() → String
inherited
A string representation of this object. [...]
write(Object? object) → void
inherited
Converts object to a String by invoking Object.toString and adds the encoding of the result to the target consumer. [...]
writeAll(Iterable objects, [String separator = ""]) → void
inherited
Iterates over the given objects and writes them in sequence. [...]
writeCharCode(int charCode) → void
inherited
Writes the character of charCode. [...]
writeln([Object? object = ""]) → void
inherited
Converts object to a String by invoking Object.toString and writes the result to this, followed by a newline. [...]

Operators

operator ==(Object other) → bool
inherited
The equality operator. [...]

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-io/HttpClientRequest-class.html