Interface HttpResponse
-
- All Superinterfaces:
AutoCloseable
public interface HttpResponse extends AutoCloseable
Represents an HTTP response message.- Since:
- 4.0.0
- Author:
- Dmytro Nosan
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Closes the response and releases any underlying resources.HttpHeadersgetHeaders()Returns the headers associated with this HTTP response.InputStreamgetInputStream()Returns the body of the HTTP response as anInputStream.intgetStatus()Returns the HTTP status code of the response.URIgetUri()Returns the URI of the HTTP request that resulted in this response.
-
-
-
Method Detail
-
getUri
URI getUri()
Returns the URI of the HTTP request that resulted in this response.- Returns:
- the URI of the associated HTTP request
-
getStatus
int getStatus()
Returns the HTTP status code of the response.- Returns:
- the HTTP status code
-
getHeaders
HttpHeaders getHeaders()
Returns the headers associated with this HTTP response.- Returns:
- a
HttpHeadersobject representing the response headers
-
getInputStream
InputStream getInputStream() throws IOException
Returns the body of the HTTP response as anInputStream.The response body is available for reading as raw byte content using this stream. It is important to ensure this stream is fully read or closed to properly release resources.
- Returns:
- an
InputStreamcontaining the response body - Throws:
IOException- if an I/O error occurs while retrieving the body
-
close
void close() throws IOExceptionCloses the response and releases any underlying resources.It is recommended to use a try-with-resources statement when working with
HttpResponseto automatically handle resource cleanup:try (HttpResponse response = client.send(request)) { InputStream body = response.getInputStream(); // Process the response body }- Specified by:
closein interfaceAutoCloseable- Throws:
IOException- if an I/O error occurs while closing the response
-
-