public final class DroidHttpClient
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
DroidHttpClient.Builder
Java builder pattern class used to set DroidHttpClient parameters.
|
static class |
DroidHttpClient.CookiePolicy |
static class |
DroidHttpClient.MultipartData
Class that manage multipart data for 'post' method.
|
static class |
DroidHttpClient.Parse
Class to manipulate the HTML content recovered.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_HEADER_USER_AGENT |
static java.lang.String |
DEFAULT_HTML_CONTENT_CHAR_SET |
static java.lang.String |
DEFAULT_SSL_PROTOCOL |
static java.lang.String |
DEFAULT_TRUSTED_KEYSTORE_TYPE |
static java.lang.String |
DEFAUTL_TRUSTED_KEYSTORE_PROVIDER |
static int |
HTTP_DEFAULT_TIMEOUT |
| Constructor and Description |
|---|
DroidHttpClient() |
| Modifier and Type | Method and Description |
|---|---|
void |
addRequestHeader(java.lang.String key,
java.lang.String value)
Add specific header fields following RFC 7230.
|
void |
clearRequestHeaders()
Remove all the header fields.
|
void |
connect(java.lang.String URL)
Connect to the URL connection.
|
void |
connect(java.lang.String URL,
java.lang.String method)
Connect to the URL connection.
|
void |
connect(java.lang.String URL,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
Connect to the URL connection.
|
void |
deleteRequestHeader(java.lang.String key)
Delete the header field.
|
static DroidHttpClient.Builder |
getBuilder()
Returns an object builder instance.
|
byte[] |
getByteArrayContent(java.lang.String URL)
Get the content from the URL connection.
|
byte[] |
getByteArrayContent(java.lang.String URL,
DroidHttpClient.MultipartData multipartData)
Get the content from the URL connection.
|
byte[] |
getByteArrayContent(java.lang.String URL,
java.lang.String method)
Get the content from the URL connection.
|
HttpEntity |
getContent(java.lang.String URL)
Get the content from the URL connection.
|
HttpEntity |
getContent(java.lang.String url,
DroidHttpClient.MultipartData multipartData)
Get the content from the URL connection.
|
HttpEntity |
getContent(java.lang.String URL,
java.lang.String method)
Get the content from the URL connection.
|
HttpEntity |
getContent(java.lang.String url,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
Get the content from the URL connection.
|
java.lang.String |
getHTMLContent(java.lang.String URL)
Get the HTML content response from the URL connection.
|
java.lang.String |
getHTMLContent(java.lang.String URL,
DroidHttpClient.MultipartData multipartData)
Get the HTML content response from the URL connection.
|
java.lang.String |
getHTMLContent(java.lang.String URL,
java.lang.String method)
Get the HTML content response from the URL connection.
|
java.lang.String |
getHTMLContent(java.lang.String URL,
java.lang.String charSet,
DroidHttpClient.MultipartData multipartData)
Get the HTML content response from the URL connection.
|
java.lang.String |
getHTMLContent(java.lang.String URL,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
Get the HTML content response from the URL connection.
|
java.lang.String |
getHTMLContent(java.lang.String URL,
java.lang.String charSet,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
Get the HTML content response from the URL connection.
|
static java.security.KeyStore |
getKeyStoreFromResource(int trustKeyStoreResource)
Build KeyStore object from resource.
|
static java.security.KeyStore |
getKeyStoreFromResource(int trustKeyStoreResource,
java.lang.String keyStorePassword)
Build KeyStore object from resource.
|
static java.security.KeyStore |
getKeyStoreFromResource(int trustKeyStoreResource,
java.lang.String keyStorePassword,
java.lang.String keyStoreType,
java.lang.String provider)
Build KeyStore object from resource.
|
int |
getLastStatusError()
Get the HTTP last status recovered.
|
java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> |
getRequestHeaders()
Return request headers set.
|
javax.net.ssl.SSLSocketFactory |
getSocketFactory()
Return a javax.net.ssl.SSLSocketFactory object instance.
|
java.io.InputStream |
getStreamContent(java.lang.String URL)
Get the content from the URL connection.
|
java.io.InputStream |
getStreamContent(java.lang.String URL,
DroidHttpClient.MultipartData multipartData)
Get the content from the URL connection.
|
java.io.InputStream |
getStreamContent(java.lang.String URL,
java.lang.String method)
Get the content from the URL connection.
|
java.io.InputStream |
getStreamContent(java.lang.String URL,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
Get the content from the URL connection.
|
boolean |
isInitialized()
Return if HttpClient is initialized.
|
void |
reset()
Reset HttpClient.
|
public static final java.lang.String DEFAULT_HEADER_USER_AGENT
public static final java.lang.String DEFAULT_HTML_CONTENT_CHAR_SET
public static final java.lang.String DEFAULT_SSL_PROTOCOL
public static final java.lang.String DEFAULT_TRUSTED_KEYSTORE_TYPE
public static final java.lang.String DEFAUTL_TRUSTED_KEYSTORE_PROVIDER
public static final int HTTP_DEFAULT_TIMEOUT
public void addRequestHeader(java.lang.String key,
java.lang.String value)
key - name of the header field.value - value of the header field.public void clearRequestHeaders()
public void connect(java.lang.String URL)
throws java.io.IOException
URL - the web site to connect.java.io.IOExceptionpublic void connect(java.lang.String URL,
java.lang.String method)
throws java.io.IOException
URL - the web site to connect.method - force GET or POST method.java.io.IOExceptionpublic void connect(java.lang.String URL,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
throws java.io.IOException
URL - the web site to connect.method - force GET or POST method.params - array of request parameters in the string format 'name=value'.fixedURL - if the URL must not be parameterized (only for POST method).java.io.IOExceptionpublic void deleteRequestHeader(java.lang.String key)
key - name of the header field.public static final DroidHttpClient.Builder getBuilder()
public final byte[] getByteArrayContent(java.lang.String URL)
throws java.io.IOException
URL - the web site to connect.java.io.IOExceptionpublic final byte[] getByteArrayContent(java.lang.String URL,
DroidHttpClient.MultipartData multipartData)
throws java.io.IOException
URL - the web site to connect.multipartData - request parameters.java.io.IOExceptionpublic final byte[] getByteArrayContent(java.lang.String URL,
java.lang.String method)
throws java.io.IOException
URL - the web site to connect.method - GET, POST or default request method.java.io.IOExceptionpublic final HttpEntity getContent(java.lang.String URL)
throws java.io.IOException
URL - the web site to connect.java.io.IOExceptionpublic final HttpEntity getContent(java.lang.String url,
DroidHttpClient.MultipartData multipartData)
throws java.io.IOException
url - the web site to connect.multipartData - request parameters.java.io.IOExceptionpublic final HttpEntity getContent(java.lang.String URL,
java.lang.String method)
throws java.io.IOException
URL - the web site to connect.method - force GET or POST method.java.io.IOExceptionpublic final HttpEntity getContent(java.lang.String url,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
throws java.io.IOException
url - the web site to connect.method - force GET or POST method.params - array of request parameters in the string format 'name=value'.fixedURL - if the URL must not be parameterized (only for POST method).java.io.IOExceptionpublic final java.lang.String getHTMLContent(java.lang.String URL)
throws java.io.IOException
URL - the web site to connect.java.io.IOExceptionpublic final java.lang.String getHTMLContent(java.lang.String URL,
DroidHttpClient.MultipartData multipartData)
throws java.io.IOException
URL - the web site to connect.multipartData - request parameters.java.io.IOExceptionpublic final java.lang.String getHTMLContent(java.lang.String URL,
java.lang.String method)
throws java.io.IOException
URL - the web site to connect.method - GET, POST or default request method.java.io.IOExceptionpublic final java.lang.String getHTMLContent(java.lang.String URL,
java.lang.String charSet,
DroidHttpClient.MultipartData multipartData)
throws java.io.IOException
URL - the web site to connect.charSet - the character codification.multipartData - request parameters.java.io.IOExceptionpublic final java.lang.String getHTMLContent(java.lang.String URL,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
throws java.io.IOException
URL - the web site to connect.method - GET, POST or default request method.params - array of request parameters in the string format 'name=value'.fixedURL - if the URL must not be parameterized (only for POST method).java.io.IOExceptionpublic final java.lang.String getHTMLContent(java.lang.String URL,
java.lang.String charSet,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
throws java.io.IOException
URL - the web site to connect.charSet - the character codification.method - GET, POST or default request method.params - array of request parameters in the string format 'name=value'.fixedURL - if the URL must not be parameterized (only for POST method).java.io.IOExceptionpublic static java.security.KeyStore getKeyStoreFromResource(int trustKeyStoreResource)
throws java.security.NoSuchProviderException,
java.security.KeyStoreException,
java.security.cert.CertificateException,
java.security.NoSuchAlgorithmException,
java.io.IOException
trustKeyStoreResource - identification of the resource to load.java.security.NoSuchProviderExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.security.NoSuchAlgorithmExceptionjava.io.IOExceptionpublic static java.security.KeyStore getKeyStoreFromResource(int trustKeyStoreResource,
java.lang.String keyStorePassword)
throws java.security.NoSuchProviderException,
java.security.KeyStoreException,
java.security.cert.CertificateException,
java.security.NoSuchAlgorithmException,
java.io.IOException
trustKeyStoreResource - identification of the resource to load.keyStorePassword - password that protects the keystore.java.security.NoSuchProviderExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.security.NoSuchAlgorithmExceptionjava.io.IOExceptionpublic static java.security.KeyStore getKeyStoreFromResource(int trustKeyStoreResource,
java.lang.String keyStorePassword,
java.lang.String keyStoreType,
java.lang.String provider)
throws java.security.NoSuchProviderException,
java.security.KeyStoreException,
java.security.cert.CertificateException,
java.security.NoSuchAlgorithmException,
java.io.IOException
trustKeyStoreResource - identification of the resource to load.keyStorePassword - password that protects the keystore.keyStoreType - type of the keystore to load ("JKS", "JCEKS", "BKS", "PKCS12", etc. More info at https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#KeyStore).provider - provider use to load the keystore. Set null if default JCA Provider must be used.java.security.NoSuchProviderExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.security.NoSuchAlgorithmExceptionjava.io.IOExceptionpublic int getLastStatusError()
public java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> getRequestHeaders()
public javax.net.ssl.SSLSocketFactory getSocketFactory()
throws java.security.UnrecoverableKeyException,
java.security.NoSuchAlgorithmException,
java.security.KeyStoreException,
java.security.NoSuchProviderException,
java.security.KeyManagementException
java.security.UnrecoverableKeyExceptionjava.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.NoSuchProviderExceptionjava.security.KeyManagementExceptionpublic final java.io.InputStream getStreamContent(java.lang.String URL)
throws java.io.IOException
URL - the web site to connect.java.io.IOExceptionpublic final java.io.InputStream getStreamContent(java.lang.String URL,
DroidHttpClient.MultipartData multipartData)
throws java.io.IOException
URL - the web site to connect.multipartData - request parameters.java.io.IOExceptionpublic final java.io.InputStream getStreamContent(java.lang.String URL,
java.lang.String method)
throws java.io.IOException
URL - the web site to connect.method - GET, POST or default request method.java.io.IOExceptionpublic final java.io.InputStream getStreamContent(java.lang.String URL,
java.lang.String method,
java.lang.String[] params,
boolean fixedURL)
throws java.io.IOException
URL - the web site to connect.method - GET, POST or default request method.params - array of request parameters in the string format 'name=value'.fixedURL - if the URL must not be parameterized (only for POST method).java.io.IOExceptionpublic boolean isInitialized()
public void reset()