Package com.squareup.okhttp
Class Response
- java.lang.Object
-
- com.squareup.okhttp.Response
-
public final class Response extends Object
An HTTP response. Instances of this class are not immutable: the response body is a one-shot value that may be consumed only once. All other properties are immutable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResponse.Builder
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResponseBodybody()CacheControlcacheControl()Returns the cache control directives for this response.ResponsecacheResponse()Returns the raw response received from the cache.List<Challenge>challenges()Returns the authorization challenges appropriate for this response's code.intcode()Returns the HTTP status code.Handshakehandshake()Returns the TLS handshake of the connection that carried this response, or null if the response was received without TLS.Stringheader(String name)Stringheader(String name, String defaultValue)Headersheaders()List<String>headers(String name)booleanisRedirect()Returns true if this response redirects to another resource.booleanisSuccessful()Returns true if the code is in [200..300), which means the request was successfully received, understood, and accepted.Stringmessage()Returns the HTTP status message or null if it is unknown.ResponsenetworkResponse()Returns the raw response received from the network.Response.BuildernewBuilder()ResponsepriorResponse()Returns the response for the HTTP redirect or authorization challenge that triggered this response, or null if this response wasn't triggered by an automatic retry.Protocolprotocol()Returns the HTTP protocol, such asProtocol.HTTP_1_1orProtocol.HTTP_1_0.Requestrequest()The wire-level request that initiated this HTTP response.StringtoString()Returns a string containing a concise, human-readable description of this object.
-
-
-
Method Detail
-
request
public Request request()
The wire-level request that initiated this HTTP response. This is not necessarily the same request issued by the application:- It may be transformed by the HTTP client. For example, the client
may copy headers like
Content-Lengthfrom the request body. - It may be the request generated in response to an HTTP redirect or authentication challenge. In this case the request URL may be different than the initial request URL.
- It may be transformed by the HTTP client. For example, the client
may copy headers like
-
protocol
public Protocol protocol()
Returns the HTTP protocol, such asProtocol.HTTP_1_1orProtocol.HTTP_1_0.
-
code
public int code()
Returns the HTTP status code.
-
isSuccessful
public boolean isSuccessful()
Returns true if the code is in [200..300), which means the request was successfully received, understood, and accepted.
-
message
public String message()
Returns the HTTP status message or null if it is unknown.
-
handshake
public Handshake handshake()
Returns the TLS handshake of the connection that carried this response, or null if the response was received without TLS.
-
headers
public Headers headers()
-
body
public ResponseBody body()
-
newBuilder
public Response.Builder newBuilder()
-
isRedirect
public boolean isRedirect()
Returns true if this response redirects to another resource.
-
networkResponse
public Response networkResponse()
Returns the raw response received from the network. Will be null if this response didn't use the network, such as when the response is fully cached. The body of the returned response should not be read.
-
cacheResponse
public Response cacheResponse()
Returns the raw response received from the cache. Will be null if this response didn't use the cache. For conditional get requests the cache response and network response may both be non-null. The body of the returned response should not be read.
-
priorResponse
public Response priorResponse()
Returns the response for the HTTP redirect or authorization challenge that triggered this response, or null if this response wasn't triggered by an automatic retry. The body of the returned response should not be read because it has already been consumed by the redirecting client.
-
challenges
public List<Challenge> challenges()
Returns the authorization challenges appropriate for this response's code. If the response code is 401 unauthorized, this returns the "WWW-Authenticate" challenges. If the response code is 407 proxy unauthorized, this returns the "Proxy-Authenticate" challenges. Otherwise this returns an empty list of challenges.
-
cacheControl
public CacheControl cacheControl()
Returns the cache control directives for this response. This is never null, even if this response contains noCache-Controlheader.
-
toString
public String toString()
Description copied from class:ObjectReturns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toStringmethod if you intend implementing your owntoStringmethod.
-
-