Package java.net.http
HTTP Client and WebSocket APIs
Provides high-level client interfaces to HTTP (versions 1.1 and 2) and low-level client interfaces to WebSocket. The main types defined are:
The protocol-specific requirements are defined in the Hypertext Transfer Protocol Version 2 (HTTP/2), the Hypertext Transfer Protocol (HTTP/1.1), and The WebSocket Protocol.
In general, asynchronous tasks execute in either the thread invoking the operation, e.g. sending an HTTP request, or by the threads supplied by the client's executor
. Dependent tasks, those that are triggered by returned CompletionStages or CompletableFutures, that do not explicitly specify an executor, execute in the same default executor
as that of
CompletableFuture
, or the invoking thread if the operation completes before the dependent task is registered.
CompletableFuture
s returned by this API will throw UnsupportedOperationException
for their obtrudeValue
and obtrudeException
methods. Invoking the cancel
method on a CompletableFuture
returned by this API may not interrupt the underlying operation, but may be useful to complete, exceptionally, dependent stages that have not already completed.
Unless otherwise stated, null
parameter values will cause methods of all classes in this package to throw NullPointerException
.
- Since:
- 11
Interface | Description |
---|---|
HttpClient.Builder | A builder of HTTP Clients. |
HttpRequest.BodyPublisher | A |
HttpRequest.Builder | A builder of HTTP requests. |
HttpResponse<T> | An HTTP response. |
HttpResponse.BodyHandler<T> | A handler for response bodies. |
HttpResponse.BodySubscriber<T> | A |
HttpResponse.PushPromiseHandler<T> | A handler for push promises. |
HttpResponse.ResponseInfo | Initial response information supplied to a |
WebSocket | A WebSocket Client. |
WebSocket.Builder | A builder of WebSocket Clients. |
WebSocket.Listener | The receiving interface of |
Class | Description |
---|---|
HttpClient | An HTTP Client. |
HttpHeaders | A read-only view of a set of HTTP headers. |
HttpRequest | An HTTP request. |
HttpRequest.BodyPublishers | Implementations of |
HttpResponse.BodyHandlers | Implementations of |
HttpResponse.BodySubscribers | Implementations of |
Enum | Description |
---|---|
HttpClient.Redirect | Defines the automatic redirection policy. |
HttpClient.Version | The HTTP protocol version. |
Exception | Description |
---|---|
HttpConnectTimeoutException | Thrown when a connection, over which an |
HttpTimeoutException | Thrown when a response is not received within a specified time period. |
WebSocketHandshakeException | Thrown when the opening handshake has failed. |