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.

Warning: Experimental OkHttp 2.0 API

This class is in beta. APIs are subject to change!
  • Method Details

    • request

      public Request request()
      The wire-level request that initiated this HTTP response. This is usually not the same request instance provided to the HTTP client:
      • It may be transformed by the HTTP client. For example, the client may have added its own Content-Encoding header to enable response compression.
      • It may be the request generated in response to an HTTP redirect. In this case the request URL may be different than the initial request URL.
    • code

      public int code()
    • header

      public String header​(String name)
    • header

      public String header​(String name, String defaultValue)
    • headers

      public List<String> headers​(String name)
    • headerNames

      public Set<String> headerNames()
    • headerCount

      public int headerCount()
    • headerName

      public String headerName​(int index)
    • headerValue

      public String headerValue​(int index)
    • body

      public Response.Body body()
    • redirectedBy

      public Response redirectedBy()
      Returns the response for the HTTP redirect that triggered this response, or null if this response wasn't triggered by an automatic redirect. The body of the returned response should not be read because it has already been consumed by the redirecting client.