HttpClient class

A client that receives content, such as web pages, from a server using the HTTP, HTTPS, HTTP2, Quic etc. protocol.

HttpClient contains a number of methods to send an HttpClientRequest to an Http server and receive an HttpClientResponse back which is a Stream. Alternatively, you can also register callbacks for different network events including but not limited to receiving the raw bytes sent by the server. For example, you can use the get, getUrl, post, and postUrl methods for GET and POST requests, respectively.

Example Usage:

final client = HttpClient();
client.getUrl(Uri.parse('https://example.com/'))
  .then((HttpClientRequest request) {
  // See [HttpClientRequest] for more info
});

Constructors

HttpClient({String userAgent = 'Dart/2.12', HttpProtocol protocol = HttpProtocol.quic, List<QuicHint> quicHints = const [], bool brotli = true, String acceptLanguage = 'en_US'})
Initiates an HttpClient with the settings provided in the arguments.

Properties

acceptLanguage String
final
brotli bool
final
hashCode int
The hash code for this object.
no setterinherited
httpClientVersion String
Version string of the Cronet Shared Library currently in use.
no setter
protocol HttpProtocol
final
quicHints List<QuicHint>
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
userAgent String
final

Methods

close({bool force = false}) → void
Shuts down the HttpClient.
delete(String host, int port, String path) Future<HttpClientRequest>
Opens a request on the basis of host, port and path using DELETE method.
deleteUrl(Uri url) Future<HttpClientRequest>
Opens a url using DELETE method.
get(String host, int port, String path) Future<HttpClientRequest>
Opens a request on the basis of host, port and path using GET method.
getUrl(Uri url) Future<HttpClientRequest>
Opens a url using GET method.
Opens a request on the basis of host, port and path using HEAD method.
headUrl(Uri url) Future<HttpClientRequest>
Opens a url using HEAD method.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open(String method, String host, int port, String path) Future<HttpClientRequest>
Opens a request on the basis of method, host, port and path using GET, PUT, POST, HEAD, PATCH, DELETE or any other method.
openUrl(String method, Uri url) Future<HttpClientRequest>
Opens a url using a method like GET, PUT, POST, HEAD, PATCH, DELETE.
patch(String host, int port, String path) Future<HttpClientRequest>
Opens a request on the basis of host, port and path using PATCH method.
patchUrl(Uri url) Future<HttpClientRequest>
Opens a url using PATCH method.
post(String host, int port, String path) Future<HttpClientRequest>
Opens a request on the basis of host, port and path using POST method.
postUrl(Uri url) Future<HttpClientRequest>
Opens a url using POST method.
put(String host, int port, String path) Future<HttpClientRequest>
Opens a request on the basis of host, port and path using PUT method.
putUrl(Uri url) Future<HttpClientRequest>
Opens a url using PUT method.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

defaultHttpPort → const int
defaultHttpsPort → const int