An HttpResponse is not created directly, but rather returned as
a result of sending an HttpRequest. An HttpResponse is
made available when the response status code and headers have been received,
and typically after the response body has also been completely received.
Whether or not the HttpResponse is made available before the response
body has been completely received depends on the BodyHandler provided when sending the HttpRequest.
This class provides methods for accessing the response status code,
headers, the response body, and the HttpRequest corresponding
to this response.
The following is an example of retrieving a response as a String:
HttpResponse<String> response = client
.send(request, BodyHandlers.ofString());
The class BodyHandlers provides implementations
of many common response handlers. Alternatively, a custom BodyHandler
implementation can be used.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | |
| public static class | HttpResponse.
Implementations of |
| public static interface | HttpResponse.
the response body type T>A |
| public static class | HttpResponse.
Implementations of |
| public static interface | |
| public static interface | HttpResponse.
Initial response information supplied to a |
| Modifier and Type | Method and Description |
|---|---|
| public T | |
| public default Optional | Returns: if present, a label identifying the connection on which the response was receivedReturns if present, a label identifying the connection on which the response was received. |
| public HttpHeaders | |
| public Optional | Returns: an Optional containing the HttpResponse, if any.Returns an |
| public HttpRequest | |
| public Optional | Returns: anOptional containing the SSLSession associated
with the responseReturns an |
| public int | |
| public URI | |
| public HttpClient. | Returns: HTTP protocol versionReturns the HTTP protocol version that was used for this response. |