Class Response
Represents a Response from an http Request. Instances of this class
are created as a result of executing a Request in a Session.
They are not created manually.
Responses can access all of the http Headers that were
returned with the response, as well as the status code, status message, and
response body. In addition, the url that this response originated from is
available. This is useful when constructing further requests based on relative
url paths.
As with Request, the body of the Response is
treated specially. Since the response may be very large (like, say, downloading
an operating system) it is critical that the responses not be cached. As a
result, once the response body has been read, any futher calls to getResponseBody
may result in an exception.
-
Method Summary
Modifier and TypeMethodDescriptionGets the url that was used to produce thisResponse.getBody()Gets the response body as a String.byte[]Gets a byte array representing the body of the response.Gets aReaderfrom which the body of the response may be read.Gets anInputStreamfrom which the body of the response may be read.Returns the Header with the given name, or null if there is no such header.Header[]Gets an array of all the Headers for this Request.Gets the Date specified in the Last-Modified header, if any.Gets the status code.Returns the status text.toString()
-
Method Details
-
getHeader
Returns the Header with the given name, or null if there is no such header. Comparisons with header names are done in a case insensitive manner.- Parameters:
name- the name to look for. This must not be null.- Returns:
- the Header with the given name.
-
getHeaders
Gets an array of all the Headers for this Request. This array will never be null. Ordering of items is not guaranteed.- Returns:
- the array of Headers for this request
-
getLastModified
Gets the Date specified in the Last-Modified header, if any. This is a special convenience method for reading the Last-Modified value. If the value associated with Last-Modified cannot be properly decoded, or if Last-Modified is not specified, then null is returned.- Returns:
-
getStatusCode
Gets the status code. SeeStatusCodefor the definitive list of status codes.- Returns:
- a code indicating the status of the response. This is never null.
-
getStatusText
Returns the status text.- Returns:
- the status text
-
getBodyAsStream
Gets anInputStreamfrom which the body of the response may be read. -
getBodyAsReader
Gets aReaderfrom which the body of the response may be read. -
getBodyAsBytes
public byte[] getBodyAsBytes()Gets a byte array representing the body of the response. -
getBody
Gets the response body as a String. -
getBaseUrl
Gets the url that was used to produce thisResponse. This url will not contain a query string (that is, no parameters). -
toString
-