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.