public class OkHttpRequestor extends HttpRequestor
HttpRequestor
implementation that uses OkHttp
v2. You can only use this if your project includes the OkHttp v2 library.
To use OkHttp v3, see OkHttp3Requestor
.
To use this, pass INSTANCE
to the DbxRequestConfig
constructor.
OkHttp3Requestor
HttpRequestor.Header, HttpRequestor.Response, HttpRequestor.Uploader
Modifier and Type | Field and Description |
---|---|
static OkHttpRequestor |
INSTANCE
A thread-safe instance of
OkHttpRequestor that connects directly
(as opposed to using a proxy). |
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS
Constructor and Description |
---|
OkHttpRequestor(com.squareup.okhttp.OkHttpClient client)
Creates a new instance of this requestor that uses
client for its requests. |
Modifier and Type | Method and Description |
---|---|
HttpRequestor.Response |
doGet(String url,
Iterable<HttpRequestor.Header> headers) |
com.squareup.okhttp.OkHttpClient |
getClient()
Returns a clone of the underlying
OkHttpClient used to make requests. |
HttpRequestor.Uploader |
startPost(String url,
Iterable<HttpRequestor.Header> headers) |
HttpRequestor.Uploader |
startPut(String url,
Iterable<HttpRequestor.Header> headers) |
public static final OkHttpRequestor INSTANCE
OkHttpRequestor
that connects directly
(as opposed to using a proxy).public OkHttpRequestor(com.squareup.okhttp.OkHttpClient client)
client
for its requests.
The OkHttpClient
will be cloned to prevent further modification.
NOTE: This constructor will not enable certificate pinning on the client. If you want
certificate pinning, use the default instance, INSTANCE
, or clone the default client
and modify it accordingly:
OkHttpClient client = OkHttpRequestor.INSTANCE.getClient(); // returns a clone client.setReadTimeout(2, TimeUnit.MINUTES); // ... other modifications HttpRequestor requestor = new OkHttpRequestor(client);
client
- OkHttpClient
to use for requests (will be cloned), never null
public com.squareup.okhttp.OkHttpClient getClient()
OkHttpClient
used to make requests.
If you want to modify the client for a particular request, create a new instance of this
requestor with the modified client.OkHttpClient
used by this requestor.public HttpRequestor.Response doGet(String url, Iterable<HttpRequestor.Header> headers) throws IOException
doGet
in class HttpRequestor
IOException
public HttpRequestor.Uploader startPost(String url, Iterable<HttpRequestor.Header> headers) throws IOException
startPost
in class HttpRequestor
IOException
public HttpRequestor.Uploader startPut(String url, Iterable<HttpRequestor.Header> headers) throws IOException
startPut
in class HttpRequestor
IOException