public final class OkHttpClient extends Object implements 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() |
List<ConnectionSpec> |
connectionSpecs() |
int |
connectTimeoutMillis()
Default connect timeout (in milliseconds).
|
CookieJar |
cookieJar() |
Dispatcher |
dispatcher() |
Dns |
dns() |
boolean |
followRedirects() |
boolean |
followSslRedirects() |
HostnameVerifier |
hostnameVerifier() |
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).
|
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. |
List<Protocol> |
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 Proxy proxy()
public ProxySelector proxySelector()
public CookieJar cookieJar()
public Cache cache()
public Dns dns()
public SocketFactory socketFactory()
public SSLSocketFactory sslSocketFactory()
public 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 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 Call newCall(Request request)
request
to be executed at some point in the future.newCall
in interface Call.Factory
public OkHttpClient.Builder newBuilder()
Copyright © 2016. All Rights Reserved.