public final class OkHttpClient extends java.lang.Object implements java.lang.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.Builder |
| Constructor and Description |
|---|
OkHttpClient() |
| Modifier and Type | Method and Description |
|---|---|
Authenticator |
authenticator() |
Cache |
cache() |
CertificatePinner |
certificatePinner() |
ConnectionPool |
connectionPool() |
java.util.List<ConnectionSpec> |
connectionSpecs() |
int |
connectTimeoutMillis()
Default connect timeout (in milliseconds).
|
CookieJar |
cookieJar() |
Dispatcher |
dispatcher() |
Dns |
dns() |
boolean |
followRedirects() |
boolean |
followSslRedirects() |
javax.net.ssl.HostnameVerifier |
hostnameVerifier() |
java.util.List<Interceptor> |
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).
|
java.util.List<Interceptor> |
networkInterceptors()
Returns an immutable list of interceptors that observe a single network request and response.
|
OkHttpClient.Builder |
newBuilder() |
Call |
newCall(Request request)
Prepares the
request to be executed at some point in the future. |
java.util.List<Protocol> |
protocols() |
java.net.Proxy |
proxy() |
Authenticator |
proxyAuthenticator() |
java.net.ProxySelector |
proxySelector() |
int |
readTimeoutMillis()
Default read timeout (in milliseconds).
|
boolean |
retryOnConnectionFailure() |
javax.net.SocketFactory |
socketFactory() |
javax.net.ssl.SSLSocketFactory |
sslSocketFactory() |
int |
writeTimeoutMillis()
Default write timeout (in milliseconds).
|
public int connectTimeoutMillis()
public int readTimeoutMillis()
public int writeTimeoutMillis()
public java.net.Proxy proxy()
public java.net.ProxySelector proxySelector()
public CookieJar cookieJar()
public Cache cache()
public Dns dns()
public javax.net.SocketFactory socketFactory()
public javax.net.ssl.SSLSocketFactory sslSocketFactory()
public javax.net.ssl.HostnameVerifier hostnameVerifier()
public CertificatePinner certificatePinner()
public Authenticator authenticator()
public Authenticator proxyAuthenticator()
public ConnectionPool connectionPool()
public boolean followSslRedirects()
public boolean followRedirects()
public boolean retryOnConnectionFailure()
public Dispatcher dispatcher()
public java.util.List<Protocol> protocols()
public java.util.List<ConnectionSpec> connectionSpecs()
public java.util.List<Interceptor> interceptors()
public java.util.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 Call newCall(Request request)
request to be executed at some point in the future.newCall in interface Call.Factorypublic OkHttpClient.Builder newBuilder()
Copyright © 2016. All Rights Reserved.