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
- bool bufferOutput
-
read / writeGet or set if the HttpClientRequest should buffer output.
- HttpConnectionInfo connectionInfo
-
read-onlyGet information about the client connection. Returns
null
if the socket is not available. - int contentLength
-
read / writeGets and sets the content length of the request. If the size of the request is not known in advance set content length to -1, which is also the default. /
-
read-onlyCookies to present to the server (in the 'cookie' header).
- Future<HttpClientResponse> done
-
read-onlyA
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. - Encoding encoding
-
read / write, inheritedThe Encoding used when writing strings. Depending on the underlying consumer this property might be mutable. /
- bool followRedirects
-
read / writeSet this property to
true
if this request should automatically follow redirects. The default istrue
. - HttpHeaders headers
-
read-onlyReturns the client request headers.
- int maxRedirects
-
read / writeSet this property to the maximum number of redirects to follow when followRedirects is
true
. If this number is exceeded theonError
callback will be called with a RedirectException. - String method
-
read-onlyThe method of the request.
- bool persistentConnection
-
read / writeGets and sets the requested persistent connection state.
- Uri uri
-
read-onlyThe uri of the request.
Constructors
Methods
-
add(
List<int> data) → void -
inheritedAdds
data
to the target consumer, ignoring encoding. -
addError(
error, [StackTrace stackTrace]) → void -
inheritedPasses the error to the target consumer as an error event.
-
addStream(
Stream<List<int>> stream) → Future -
inheritedAdds all elements of the given
stream
tothis
. -
close(
) → Future<HttpClientResponse> - Close the request for input. Returns the value of done.
-
flush(
) → Future -
inheritedReturns a Future that completes once all buffered data is accepted by the to underlying StreamConsumer.
-
write(
Object obj) → void -
inheritedConverts
obj
to a String by invoking Object.toString and adds the encoding of the result to the target consumer. -
writeAll(
Iterable objects, [String separator = ""]) → void -
inheritedIterates over the given
objects
and writes them in sequence. -
writeCharCode(
int charCode) → void -
inheritedWrites the
charCode
tothis
. -
writeln(
[Object obj = ""]) → void -
inheritedConverts
obj
to a String by invoking Object.toString and writes the result tothis
, followed by a newline.