Class Response

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class Response
    extends Object
    implements Closeable
    An HTTP response.

    This response may contain a non-null body stream of the HttpUrlConnection. If so, this body must be closed to avoid leaking resources. Use either getBody() or close() to close the body.

    • Method Detail

      • isSuccessful

        public boolean isSuccessful()
      • getBody

        public String getBody()
                       throws IOException
        Returns the response body as a string, closing the stream that backs it. Idempotent.
        Returns:
        body as string
        Throws:
        IOException - IO Exception
      • getStream

        public InputStream getStream()
        Obtains the meaningful stream of the HttpUrlConnection, either inputStream or errorInputStream, depending on the status code
        Returns:
        input stream / error stream
      • getCode

        public int getCode()
        Obtains the HTTP status code
        Returns:
        the status code
      • getMessage

        public String getMessage()
        Obtains the HTTP status message. Returns null if the message can not be discerned from the response (not valid HTTP)
        Returns:
        the status message
      • getHeaders

        public Map<String,​String> getHeaders()
        Obtains a Map containing the HTTP Response Headers
        Returns:
        headers
      • getHeader

        public String getHeader​(String name)
        Obtains a single HTTP Header value, or null if undefined
        Parameters:
        name - the header name.
        Returns:
        header value or null.