HttpClient provides an efficient, asynchronous, non-blocking implementation to perform HTTP requests to a server through a simple API that offers also blocking semantic.
HttpClient provides easy-to-use methods such as GET(String) that allow to perform HTTP
requests in a one-liner, but also gives the ability to fine tune the configuration of requests via
HttpClient#newRequest(URI).
HttpClient acts as a central configuration point for network parameters (such as idle timeouts) and HTTP parameters (such as whether to follow redirects).
HttpClient transparently pools connections to servers, but allows direct control of connections for cases where this is needed.
HttpClient also acts as a central configuration point for cookies, via getHttpCookieStore().
Typical usage:
HttpClient httpClient = new HttpClient();
httpClient.start();
// One liner:
httpClient.GET("http://localhost:8080/").getStatus();
// Building a request with a timeout
ContentResponse response = httpClient.newRequest("http://localhost:8080")
.timeout(5, TimeUnit.SECONDS)
.send();
int status = response.status();
// Asynchronously
httpClient.newRequest("http://localhost:8080").send(new Response.CompleteListener()
{
@Override
public void onComplete(Result result)
{
...
}
});
| Modifier and Type | Field and Description |
|---|---|
| private long | |
| private HttpField | |
| private AuthenticationStore | |
| private final ClientConnector | |
| private static final SetCookieParser | |
| private HttpCookieStore | |
| private final ContentDecoder. | |
| private String | |
| private long | |
| private final ConcurrentMap | |
| private Sweeper | |
| private boolean | |
| private final ProtocolHandlers | |
| private HttpCompliance | |
| private static final Logger | |
| private int | |
| private int | |
| private int | |
| private int | |
| private String | |
| private final ProxyConfiguration | |
| private int | |
| private final RequestListeners | |
| private SocketAddressResolver | |
| private int | |
| private boolean | |
| private final HttpClientTransport | |
| private boolean | |
| private boolean | |
| public static final String |
| Access | Constructor and Description |
|---|---|
| public | HttpClient()
Creates a HttpClient instance that can perform HTTP/1.1 requests to non-TLS and TLS destinations. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Request | |
| public Origin | |
| protected void | doStart()
Overrides org. Starts the managed lifecycle beans in the order they were added. |
| protected void | doStop()
Overrides org. Stops the managed lifecycle beans in the reverse order they were added. |
| public ProtocolHandler | |
| public ContentResponse | Returns: theContentResponse for the requestthe URI to POST uri, Fields the fields composing the form name/value pairs fields)Performs a POST request to the specified URI with the given form parameters. |
| public ContentResponse | Returns: theContentResponse for the requestthe URI to POST uri, Fields the fields composing the form name/value pairs fields)Performs a POST request to the specified URI with the given form parameters. |
| public ContentResponse | Returns: theContentResponse for the requestthe URI to GET uri)Performs a GET request to the specified URI. |
| public ContentResponse | Returns: theContentResponse for the requestthe URI to GET uri)Performs a GET request to the specified URI. |
| public long | getAddressResolutionTimeout()
Returns: the timeout, in milliseconds, for the default |
| public AuthenticationStore | Returns: the authentication store associated with this instanceGet the authentication store associated with this instance. |
| public SocketAddress | |
| public ByteBufferPool | Returns: theByteBufferPool of this HttpClientGet the |
| public long | getConnectTimeout()
Returns: the max time, in milliseconds, a connection can take to connect to destinations. |
| public ContentDecoder. | Returns: a set ofContentDecoder. that can be used to add and remove content decoder factoriesReturns a non thread-safe set of |
| public String | |
| public long | Returns: the time in ms after which idle destinations are removedThe default value is 0 |
| public List | |
| public Executor | |
| public HttpCompliance | Returns: the HttpCompliance instanceGets the http compliance mode for parsing http responses. |
| public HttpCookieStore | Returns: the cookie store associated with this instanceGet the cookie store associated with this instance. |
| public long | getIdleTimeout()
Returns: the max time, in milliseconds, a connection can be idle (that is, without traffic of bytes in either direction) |
| public int | getMaxConnectionsPerDestination()
Returns: the max number of connections that this HttpClient opens to |
| public int | |
| public int | getMaxRequestsQueuedPerDestination()
Returns: the max number of requests that may be queued to a |
| public int | |
| public String | |
| public ProtocolHandlers | |
| public ProxyConfiguration | |
| public int | |
| public RequestListeners | Returns: aRequestListeners instance that can be used to add request listenersReturns a non thread-safe container of |
| public int | |
| public Scheduler | |
| public SocketAddressResolver | Returns: theSocketAddressResolver of this HttpClientGet the |
| public SslContextFactory. | |
| public HttpClientTransport | |
| public HttpField | Returns: the "User-Agent" HTTP field of this HttpClientGet the "User-Agent" HTTP field of this HttpClient. |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | |
| public void | |
| private HttpConversation | |
| private HttpRequest | |
| public Request | Returns: the request just createdthe request host host, int the request port port)Creates a new request with the "http" scheme and the specified host and port |
| public Request | Returns: the request just createdthe request absolute URI uri)Creates a new request with the specified absolute URI in string format. |
| public Request | Returns: the request just createdthe request absolute URI uri)Creates a new request with the specified absolute URI. |
| public ClientConnectionFactory | newSslClientConnectionFactory(SslContextFactory.
|
| public static int | |
| public Request | |
| public Request | |
| public void | |
| public boolean | |
| public Destination | |
| public Destination | Returns: the destination for the given originthe origin that identifies the destination origin)Returns, creating it if absent, the destination with the given origin. |
| public void | setAddressResolutionTimeout(long
the timeout, in milliseconds, for the default addressResolutionTimeout)SocketAddressResolver created at startupSets the socket address resolution timeout used by the default |
| public void | setAuthenticationStore(AuthenticationStore
the authentication store associated with this instance authenticationStore)Set the authentication store associated with this instance. |
| public void | |
| public void | setByteBufferPool(ByteBufferPool
the byteBufferPool)ByteBufferPool of this HttpClientSet the |
| public void | setConnectBlocking(boolean
whether connectBlocking)connect() operations are performed in blocking modeWhether |
| public void | setConnectTimeout(long
the max time, in milliseconds, a connection can take to connect to destinations. Zero value means infinite timeout. connectTimeout)
|
| public void | setDefaultRequestContentType(String
the default content type for request content contentType)Set the default content type for request content. |
| public void | setDestinationIdleTimeout(long
the time in ms after which idle destinations are removed destinationIdleTimeout)Whether destinations that have no connections (nor active nor idle) and no exchanges should be removed after the specified timeout. |
| public void | |
| public void | |
| public void | setHttpCompliance(HttpCompliance
The compliance level which is used to actually parse http responses httpCompliance)Sets the http compliance mode for parsing http responses. |
| public void | setHttpCookieStore(HttpCookieStore
the cookie store associated with this instance cookieStore)Set the cookie store associated with this instance. |
| public void | setIdleTimeout(long
the max time, in milliseconds, a connection can be idle (that is, without traffic of bytes in either direction) idleTimeout)Set the max time, in milliseconds, a connection can be idle (that is, without traffic of bytes in either direction). |
| public void | setMaxConnectionsPerDestination(int
the max number of connections that this HttpClient opens to maxConnectionsPerDestination)DestinationsSets the max number of connections to open to each destinations. |
| public void | setMaxRedirects(int
the max number of HTTP redirects that are followed in a conversation, or -1 for unlimited redirects maxRedirects)
|
| public void | setMaxRequestsQueuedPerDestination(int
the max number of requests that may be queued to a maxRequestsQueuedPerDestination)Destination.Sets the max number of requests that may be queued to a destination. |
| public void | setMaxResponseHeadersSize(int
the max size in bytes of the response headers maxResponseHeadersSize)Set the max size in bytes of the response headers. |
| public void | |
| public void | setRequestBufferSize(int
the size of the buffer (in bytes) used to write requests requestBufferSize)Set the size of the buffer (in bytes) used to write requests. |
| public void | setResponseBufferSize(int
the size of the buffer used to read responses responseBufferSize)Set the size of the buffer used to read responses. |
| public void | setScheduler(Scheduler
the scheduler)Scheduler of this HttpClientSet the |
| public void | setSocketAddressResolver(SocketAddressResolver
the resolver)SocketAddressResolver of this HttpClientSet the |
| public void | setSslContextFactory(SslContextFactory.
the sslContextFactorySslContextFactory. that manages TLS encryptionSet the |
| public void | setStrictEventOrdering(boolean
whether request/response events must be strictly ordered strictEventOrdering)Whether request/response events must be strictly ordered with respect to connection usage. |
| public void | setUseInputDirectByteBuffers(boolean
whether to use direct ByteBuffers for reading useInputDirectByteBuffers)Set whether to use direct ByteBuffers for reading. |
| public void | setUseOutputDirectByteBuffers(boolean
whether to use direct ByteBuffers for writing useOutputDirectByteBuffers)Set whether to use direct ByteBuffers for writing. |
| public void | setUserAgentField(HttpField
the "User-Agent" HTTP header string of this HttpClient agent)Set the "User-Agent" HTTP header string of this HttpClient. |