Interface HttpResponse
public interface HttpResponse
A server's response to a HTTP request.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA processor for response bodies, which determines the type of the response body returned from HttpResponse. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpResponse.BodyProcessor<byte[]>static HttpResponse.BodyProcessor<Map<String,Object>> asJsonObject(Json jsonService) Returns a response processor which decodes a JSON body using the character set specified in the Content-Type response header.static HttpResponse.BodyProcessor<String>asString()Returns a response processor which decodes the body using the character set specified in the Content-Type response header.<T> Tbody(HttpResponse.BodyProcessor<T> processor) Returns the body of this response, as processed by the passedHttpResponse.BodyProcessor.headers()static HttpResponse.BodyProcessor<Void>request()inturi()Returns the URI that the response was received from.
-
Method Details
-
statusCode
int statusCode()- Returns:
- the status code for this response
-
request
HttpRequest request()- Returns:
- the HttpRequest for this response
-
uri
URI uri()Returns the URI that the response was received from. This may be different from the request URI if redirection occurred.- Returns:
- the URI of the response
-
body
Returns the body of this response, as processed by the passedHttpResponse.BodyProcessor.- Type Parameters:
T- the type of the returned body object- Parameters:
processor- the processor to handle the response body- Returns:
- the body of this response, as an instance of type
T - Throws:
UncheckedIOException- if an I/O error occurs reading the response
-
headers
HttpHeaders headers()- Returns:
- the received response headers
-
ignoreBody
- Returns:
- a HttpResponse.BodyProcessor<byte[]> which ignores the response body and closes the connection.
-
asByteArray
- Returns:
- a HttpResponse.BodyProcessor<byte[]> which returns the response body as a byte array.
-
asString
Returns a response processor which decodes the body using the character set specified in the Content-Type response header. If there is no such header, or the character set is not supported, then UTF-8 is used.- Returns:
- a HttpResponse.BodyProcessor<String> which returns the response body as a String.
-
asJsonObject
Returns a response processor which decodes a JSON body using the character set specified in the Content-Type response header. If there is no such header, or the character set is not supported, then UTF-8 is used. If theContent-Typeresponse header exists and is not compatible with JSON, aRuntimeExceptionis thrown when the response is processed.- Parameters:
jsonService- theJsonservice to use to parse the message body- Returns:
- a
HttpResponse.BodyProcessor<Map<String, Object>>which returns the response body as a Map. - Since:
- 4.0.0
-