public class OkHttpClient extends Objectimplements Cloneable , Call .Factory
To create an OkHttpClient with the default settings, use the default constructor. Or create a configured instance with OkHttpClient.Builder. To adjust an existing client before making a request, use newBuilder(). This example shows a call with a 30 second timeout:
OkHttpClient client = ... OkHttpClient clientWith30sTimeout = client.newBuilder() .readTimeout(30, TimeUnit.SECONDS) .build(); Response response = clientWith30sTimeout.newCall(request).execute();
| Modifier and Type | Class and Description |
|---|---|
static class |
OkHttpClient
|
| Constructor and Description |
|---|
OkHttpClient()
|
| Modifier and Type | Method and Description |
|---|---|
Authenticator |
authenticator()
|
Cache |
cache()
|
CertificatePinner |
certificatePinner()
|
ConnectionPool |
connectionPool()
|
List |
connectionSpecs()
|
int |
connectTimeoutMillis()
Default connect timeout (in milliseconds).
|
CookieJar |
cookieJar()
|
Dispatcher |
dispatcher()
|
Dns |
dns()
|
boolean |
followRedirects()
|
boolean |
followSslRedirects()
|
HostnameVerifier |
hostnameVerifier()
|
List |
interceptors()
Returns an immutable list of interceptors that observe the full span of each call: from before the connection is established (if any) until after the response source is selected (either the origin server, cache, or both).
|
List |
networkInterceptors()
Returns an immutable list of interceptors that observe a single network request and response.
|
OkHttpClient |
newBuilder()
|
Call |
newCall(Request
Prepares the
request to be executed at some point in the future.
|
List |
protocols()
|
Proxy |
proxy()
|
Authenticator |
proxyAuthenticator()
|
ProxySelector |
proxySelector()
|
int |
readTimeoutMillis()
Default read timeout (in milliseconds).
|
boolean |
retryOnConnectionFailure()
|
SocketFactory |
socketFactory()
|
SSLSocketFactory |
sslSocketFactory()
|
int |
writeTimeoutMillis()
Default write timeout (in milliseconds).
|
public int connectTimeoutMillis()
public int readTimeoutMillis()
public int writeTimeoutMillis()
public Proxyproxy()
public ProxySelectorproxySelector()
public CookieJarcookieJar()
public Cachecache()
public Dnsdns()
public SocketFactorysocketFactory()
public SSLSocketFactorysslSocketFactory()
public HostnameVerifierhostnameVerifier()
public CertificatePinnercertificatePinner()
public Authenticatorauthenticator()
public AuthenticatorproxyAuthenticator()
public ConnectionPoolconnectionPool()
public boolean followSslRedirects()
public boolean followRedirects()
public boolean retryOnConnectionFailure()
public Dispatcherdispatcher()
public List<ConnectionSpec > connectionSpecs()
public List<Interceptor > interceptors()
public List<Interceptor > networkInterceptors()
Interceptor.Chain.proceed(okhttp3.Request) exactly once: it is an error for a network interceptor to short-circuit or repeat a network request.
public CallnewCall(Request request)
request to be executed at some point in the future.
public OkHttpClient.Builder newBuilder()