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.CONTENT_TYPE, "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.

Implements

Properties

bufferOutput bool

read / write
connectionInfo HttpConnectionInfo

Get information about the client connection. Returns null if the socket is not available.

read-only
contentLength int

read / write
cookies List<Cookie>

Cookies to present to the server (in the 'cookie' header).

read-only
done Future<HttpClientResponse>

A HttpClientResponse future that will complete once the response is available. If an error occurs before the response is available, this future will complete with an error.

read-only
encoding Encoding

read / write, inherited
followRedirects bool

read / write
hashCode int

Get a hash code for this object.

read-only, inherited
headers HttpHeaders

Returns the client request headers.

read-only
maxRedirects int

read / write
method String

The method of the request.

read-only
persistentConnection bool

read / write
runtimeType Type

A representation of the runtime type of the object.

read-only, inherited
uri Uri

The uri of the request.

read-only

Constructors

HttpClientRequest()

Operators

operator ==(other) bool

The equality operator.

inherited

Methods

add(List<int> data) → void

Adds data to the target consumer, ignoring encoding.

inherited
addError(error, [StackTrace stackTrace]) → void

Passes the error to the target consumer as an error event.

inherited
addStream(Stream<List<int>> stream)

Adds all elements of the given stream to this.

inherited
close() Future<HttpClientResponse>

Close the request for input. Returns the value of done.

flush()

Returns a Future that completes once all buffered data is accepted by the to underlying StreamConsumer.

inherited
noSuchMethod(Invocation invocation) → dynamic

noSuchMethod is invoked when users invoke a non-existent method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod in an Invocation. If noSuchMethod returns a value, that value becomes the result of the original invocation.

inherited
toString() String

Returns a string representation of this object.

inherited
write(Object obj) → void

Converts obj to a String by invoking Object.toString and adds the encoding of the result to the target consumer.

inherited
writeAll(objects, [String separator = ""]) → void

Iterates over the given objects and writes them in sequence.

inherited
writeCharCode(int charCode) → void

Writes the charCode to this.

inherited
writeln([Object obj = ""]) → void

Converts obj to a String by invoking Object.toString and writes the result to this, followed by a newline.

inherited