public final class OkHttpClient extends Object implements URLStreamHandlerFactory, Cloneable
clone() to make a shallow copy of the OkHttpClient that can be
safely modified with further configuration changes.| Constructor and Description |
|---|
OkHttpClient() |
| Modifier and Type | Method and Description |
|---|---|
OkHttpClient |
clone()
Returns a shallow copy of this OkHttpClient.
|
URLStreamHandler |
createURLStreamHandler(String protocol)
Deprecated.
moved to
OkUrlFactory.createURLStreamHandler. |
OkAuthenticator |
getAuthenticator() |
Cache |
getCache() |
ConnectionPool |
getConnectionPool() |
int |
getConnectTimeout()
Default connect timeout (in milliseconds).
|
CookieHandler |
getCookieHandler() |
boolean |
getFollowProtocolRedirects()
Deprecated.
moved to
getFollowSslRedirects(). |
boolean |
getFollowSslRedirects() |
HostnameVerifier |
getHostnameVerifier() |
OkResponseCache |
getOkResponseCache()
Deprecated.
replaced by
getCache() which doesn't support custom
cache implementations. |
List<Protocol> |
getProtocols() |
Proxy |
getProxy() |
ProxySelector |
getProxySelector() |
int |
getReadTimeout()
Default read timeout (in milliseconds).
|
ResponseCache |
getResponseCache()
Deprecated.
replaced by
getCache() which doesn't support custom
cache implementations. |
RouteDatabase |
getRoutesDatabase()
Deprecated.
removed from the public API in OkHttp 2.0.
|
SSLSocketFactory |
getSslSocketFactory() |
List<String> |
getTransports()
Deprecated.
OkHttp 1.5 enforces an enumeration of
protocols that can be selected. Please switch to getProtocols(). |
HttpURLConnection |
open(URL url)
Deprecated.
moved to
OkUrlFactory.open. |
OkHttpClient |
setAuthenticator(OkAuthenticator authenticator)
Sets the authenticator used to respond to challenges from the remote web
server or proxy server.
|
OkHttpClient |
setCache(Cache cache) |
OkHttpClient |
setConnectionPool(ConnectionPool connectionPool)
Sets the connection pool used to recycle HTTP and HTTPS connections.
|
void |
setConnectTimeout(long timeout,
TimeUnit unit)
Sets the default connect timeout for new connections.
|
OkHttpClient |
setCookieHandler(CookieHandler cookieHandler)
Sets the cookie handler to be used to read outgoing cookies and write
incoming cookies.
|
OkHttpClient |
setFollowProtocolRedirects(boolean followProtocolRedirects)
Deprecated.
moved to
setFollowSslRedirects(boolean). |
OkHttpClient |
setFollowSslRedirects(boolean followProtocolRedirects)
Configure this client to follow redirects from HTTPS to HTTP and from HTTP
to HTTPS.
|
OkHttpClient |
setHostnameVerifier(HostnameVerifier hostnameVerifier)
Sets the verifier used to confirm that response certificates apply to
requested hostnames for HTTPS connections.
|
OkHttpClient |
setOkResponseCache(OkResponseCache responseCache)
Deprecated.
replaced by
setCache(com.squareup.okhttp.Cache) which doesn't support custom
cache implementations. |
OkHttpClient |
setProtocols(List<Protocol> protocols)
Configure the protocols used by this client to communicate with remote
servers.
|
OkHttpClient |
setProxy(Proxy proxy)
Sets the HTTP proxy that will be used by connections created by this
client.
|
OkHttpClient |
setProxySelector(ProxySelector proxySelector)
Sets the proxy selection policy to be used if no
proxy
is specified explicitly. |
void |
setReadTimeout(long timeout,
TimeUnit unit)
Sets the default read timeout for new connections.
|
OkHttpClient |
setResponseCache(ResponseCache responseCache)
Deprecated.
replaced by
setCache(com.squareup.okhttp.Cache) which doesn't support custom
cache implementations. |
OkHttpClient |
setSslSocketFactory(SSLSocketFactory sslSocketFactory)
Sets the socket factory used to secure HTTPS connections.
|
OkHttpClient |
setTransports(List<String> transports)
Deprecated.
OkHttp 1.5 enforces an enumeration of
protocols
that can be selected. Please switch to setProtocols(java.util.List). |
public void setConnectTimeout(long timeout,
TimeUnit unit)
URLConnection.setConnectTimeout(int)public int getConnectTimeout()
public void setReadTimeout(long timeout,
TimeUnit unit)
URLConnection.setReadTimeout(int)public int getReadTimeout()
public OkHttpClient setProxy(Proxy proxy)
setProxySelector(java.net.ProxySelector), which is
only honored when this proxy is null (which it is by default). To disable
proxy use completely, call setProxy(Proxy.NO_PROXY).public Proxy getProxy()
public OkHttpClient setProxySelector(ProxySelector proxySelector)
proxy
is specified explicitly. The proxy selector may return multiple proxies;
in that case they will be tried in sequence until a successful connection
is established.
If unset, the system-wide default
proxy selector will be used.
public ProxySelector getProxySelector()
public OkHttpClient setCookieHandler(CookieHandler cookieHandler)
If unset, the system-wide default
cookie handler will be used.
public CookieHandler getCookieHandler()
@Deprecated public OkHttpClient setResponseCache(ResponseCache responseCache)
setCache(com.squareup.okhttp.Cache) which doesn't support custom
cache implementations.@Deprecated public ResponseCache getResponseCache()
getCache() which doesn't support custom
cache implementations.@Deprecated public OkHttpClient setOkResponseCache(OkResponseCache responseCache)
setCache(com.squareup.okhttp.Cache) which doesn't support custom
cache implementations.@Deprecated public OkResponseCache getOkResponseCache()
getCache() which doesn't support custom
cache implementations.public OkHttpClient setCache(Cache cache)
public Cache getCache()
public OkHttpClient setSslSocketFactory(SSLSocketFactory sslSocketFactory)
If unset, a lazily created SSL socket factory will be used.
public SSLSocketFactory getSslSocketFactory()
public OkHttpClient setHostnameVerifier(HostnameVerifier hostnameVerifier)
If unset, the
system-wide default hostname verifier will be used.
public HostnameVerifier getHostnameVerifier()
public OkHttpClient setAuthenticator(OkAuthenticator authenticator)
If unset, the system-wide default
authenticator will be used.
public OkAuthenticator getAuthenticator()
public OkHttpClient setConnectionPool(ConnectionPool connectionPool)
If unset, the system-wide
default connection pool will be used.
public ConnectionPool getConnectionPool()
@Deprecated public OkHttpClient setFollowProtocolRedirects(boolean followProtocolRedirects)
setFollowSslRedirects(boolean).@Deprecated public boolean getFollowProtocolRedirects()
getFollowSslRedirects().public OkHttpClient setFollowSslRedirects(boolean followProtocolRedirects)
If unset, protocol redirects will be followed. This is different than
the built-in HttpURLConnection's default.
public boolean getFollowSslRedirects()
@Deprecated public RouteDatabase getRoutesDatabase()
@Deprecated public OkHttpClient setTransports(List<String> transports)
protocols
that can be selected. Please switch to setProtocols(java.util.List).public OkHttpClient setProtocols(List<Protocol> protocols)
The following protocols are currently supported:
This is an evolving set. Future releases may drop support for transitional protocols (like spdy/3.1), in favor of their successors (spdy/4 or http/2.0). The http/1.1 transport will never be dropped.
If multiple protocols are specified, NPN will be used to negotiate a transport. Future releases may use another mechanism (such as ALPN) to negotiate a transport.
protocols - the protocols to use, in order of preference. The list
must contain "http/1.1". It must not contain null.@Deprecated public List<String> getTransports()
protocols that can be selected. Please switch to getProtocols().@Deprecated public HttpURLConnection open(URL url)
OkUrlFactory.open.public OkHttpClient clone()
@Deprecated public URLStreamHandler createURLStreamHandler(String protocol)
OkUrlFactory.createURLStreamHandler.URL.setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory).
This code configures OkHttp to handle all HTTP and HTTPS connections
created with URL.openConnection():
OkHttpClient okHttpClient = new OkHttpClient();
URL.setURLStreamHandlerFactory(okHttpClient);
createURLStreamHandler in interface URLStreamHandlerFactoryCopyright © 2014. All Rights Reserved.