public class HttpClient
extends okhttp3.OkHttpClient
HttpClient
contains the recommended API for handling web requests.
It utilizes the OkHttpClient
library for efficient request handling.
Request caching is not enabled by default because of potential file conflict in the event of multiple client instances being run at the same time.
Constructor | Description |
---|---|
HttpClient() |
Modifier and Type | Method | Description |
---|---|---|
void |
downloadFileAsync(java.lang.String url,
java.nio.file.Path savePath) |
Performs an asynchronous download of the file from the URL specified, to the save path specified.
|
void |
downloadFileSync(java.lang.String url,
java.nio.file.Path savePath) |
Performs a synchronous download of the file from the URL specified, to the save path specified.
|
void |
downloadUrlAsync(java.lang.String url,
okhttp3.Callback callback) |
Constructs an asynchronous request to the URL specified, and places it on the OkHttp worker thread.
|
okhttp3.Response |
downloadUrlSync(java.lang.String url) |
Constructs a synchronous request to the URL specified.
|
int |
getContentLength(java.lang.String url) |
Sends a HEAD request to the URL specified and returns the value of the Content-Length response header.
|
okhttp3.Request.Builder |
getRequestBuilder() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
authenticator, cache, certificatePinner, connectionPool, connectionSpecs, connectTimeoutMillis, cookieJar, dispatcher, dns, eventListenerFactory, followRedirects, followSslRedirects, hostnameVerifier, interceptors, networkInterceptors, newBuilder, newCall, newWebSocket, pingIntervalMillis, protocols, proxy, proxyAuthenticator, proxySelector, readTimeoutMillis, retryOnConnectionFailure, socketFactory, sslSocketFactory, writeTimeoutMillis
public void downloadFileSync(java.lang.String url, java.nio.file.Path savePath) throws java.io.IOException
url
- the URL of the filesavePath
- the save path of the downloaded filejava.io.IOException
- if the download failedpublic void downloadFileAsync(java.lang.String url, java.nio.file.Path savePath) throws java.io.IOException
url
- the URL of the filesavePath
- the save path of the downloaded filejava.io.IOException
- if the download failedpublic okhttp3.Response downloadUrlSync(java.lang.String url) throws java.io.IOException
url
- the URL of a requestjava.io.IOException
- if the download failedpublic void downloadUrlAsync(java.lang.String url, okhttp3.Callback callback) throws java.io.IOException
Callback
specified in the arguments is called upon completion of the request.url
- the URL of your requestcallback
- the Callback
called after request completionjava.io.IOException
- if the download failedpublic int getContentLength(java.lang.String url) throws java.io.IOException, java.lang.NumberFormatException
url
- the URL to get the Content-Length ofjava.io.IOException
- if the download failedjava.lang.NumberFormatException
- if the Content-Length returned is not a numberpublic okhttp3.Request.Builder getRequestBuilder()