Dart API Referencedart:ioHttpClient

HttpClient abstract class

HTTP client factory. The HttpClient handles all the sockets associated with the HttpClientConnections and when the endpoint supports it, it will try to reuse opened sockets for several requests to support HTTP 1.1 persistent connections. This means that sockets will be kept open for some time after a requests have completed, unless HTTP procedures indicate that it must be closed as part of completing the request. Use HttpClient.shutdown to force close the idle sockets.

abstract class HttpClient {
  static const int DEFAULT_HTTP_PORT = 80;

  factory HttpClient() => new _HttpClient();

  /**
   * Opens a HTTP connection. The returned [HttpClientConnection] is
   * used to register callbacks for asynchronous events on the HTTP
   * connection. The "Host" header for the request will be set to the
   * value [host]:[port]. This can be overridden through the
   * HttpClientRequest interface before the request is sent. NOTE if
   * [host] is an IP address this will still be set in the "Host"
   * header.
   */
  HttpClientConnection open(String method, String host, int port, String path);

  /**
   * Opens a HTTP connection. The returned [HttpClientConnection] is
   * used to register callbacks for asynchronous events on the HTTP
   * connection. The "Host" header for the request will be set based
   * the host and port specified in [url]. This can be overridden
   * through the HttpClientRequest interface before the request is
   * sent. NOTE if the host is specified as an IP address this will
   * still be set in the "Host" header.
   */
  HttpClientConnection openUrl(String method, Uri url);

  /**
   * Opens a HTTP connection using the GET method. See [open] for
   * details. Using this method to open a HTTP connection will set the
   * content length to 0.
   */
  HttpClientConnection get(String host, int port, String path);

  /**
   * Opens a HTTP connection using the GET method. See [openUrl] for
   * details. Using this method to open a HTTP connection will set the
   * content length to 0.
   */
  HttpClientConnection getUrl(Uri url);

  /**
   * Opens a HTTP connection using the POST method. See [open] for details.
   */
  HttpClientConnection post(String host, int port, String path);

  /**
   * Opens a HTTP connection using the POST method. See [openUrl] for details.
   */
  HttpClientConnection postUrl(Uri url);

  /**
   * Sets the function used to resolve the proxy server to be used for
   * opening a HTTP connection to the specified [url]. If this
   * function is not set, direct connections will always be used.
   *
   * The string returned by [f] must be in the format used by browser
   * PAC (proxy auto-config) scripts. That is either
   *
   *   "DIRECT"
   *
   * for using a direct connection or
   *
   *   "PROXY host:port"
   *
   * for using the proxy server [:host:] on port [:port:].
   *
   * A configuration can contain several configuration elements
   * separated by semicolons, e.g.
   *
   *   "PROXY host:port; PROXY host2:port2; DIRECT"
   */
  set findProxy(String f(Uri url));

  /**
   * Shutdown the HTTP client releasing all resources.
   */
  void shutdown();
}

Static Properties

const int DEFAULT_HTTP_PORT #

static const int DEFAULT_HTTP_PORT = 80;

Constructors

factory HttpClient() #

factory HttpClient() => new _HttpClient();

Properties

set findProxy(String f(Uri url)) #

Sets the function used to resolve the proxy server to be used for opening a HTTP connection to the specified url. If this function is not set, direct connections will always be used.

The string returned by f must be in the format used by browser PAC (proxy auto-config) scripts. That is either

"DIRECT"

for using a direct connection or

"PROXY host:port"

for using the proxy server host on port port.

A configuration can contain several configuration elements separated by semicolons, e.g.

"PROXY host:port; PROXY host2:port2; DIRECT"

set findProxy(String f(Uri url));

Methods

HttpClientConnection get(String host, int port, String path) #

Opens a HTTP connection using the GET method. See open for details. Using this method to open a HTTP connection will set the content length to 0.

HttpClientConnection get(String host, int port, String path);

HttpClientConnection getUrl(Uri url) #

Opens a HTTP connection using the GET method. See openUrl for details. Using this method to open a HTTP connection will set the content length to 0.

HttpClientConnection getUrl(Uri url);

HttpClientConnection open(String method, String host, int port, String path) #

Opens a HTTP connection. The returned HttpClientConnection is used to register callbacks for asynchronous events on the HTTP connection. The "Host" header for the request will be set to the value host: port. This can be overridden through the HttpClientRequest interface before the request is sent. NOTE if host is an IP address this will still be set in the "Host" header.

HttpClientConnection open(String method, String host, int port, String path);

HttpClientConnection openUrl(String method, Uri url) #

Opens a HTTP connection. The returned HttpClientConnection is used to register callbacks for asynchronous events on the HTTP connection. The "Host" header for the request will be set based the host and port specified in url. This can be overridden through the HttpClientRequest interface before the request is sent. NOTE if the host is specified as an IP address this will still be set in the "Host" header.

HttpClientConnection openUrl(String method, Uri url);

HttpClientConnection post(String host, int port, String path) #

Opens a HTTP connection using the POST method. See open for details.

HttpClientConnection post(String host, int port, String path);

HttpClientConnection postUrl(Uri url) #

Opens a HTTP connection using the POST method. See openUrl for details.

HttpClientConnection postUrl(Uri url);

void shutdown() #

Shutdown the HTTP client releasing all resources.

void shutdown();