public class OkHttpTool extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
DELETE |
static String |
GET |
static String |
POST |
static String |
PUT |
| Constructor and Description |
|---|
OkHttpTool()
Constructor with no Context.
|
OkHttpTool(android.content.Context context)
Constructor with a Context to install a ResponseCache
|
| Modifier and Type | Method and Description |
|---|---|
HttpURLConnection |
delete(String url)
Basic DELETE Request
|
HttpURLConnection |
get(String url)
Basic GET Request
|
BufferedReader |
getBufferedInputReader(HttpURLConnection connection) |
com.squareup.okhttp.OkHttpClient |
getClient()
Just in case you want to set the client up more than it already is.
|
Map<String,String> |
getDefaultHeaders()
Returns the default request headers
|
HttpURLConnection |
post(String url,
org.apache.http.entity.StringEntity entity)
Basic POST Request
|
HttpURLConnection |
put(String url,
org.apache.http.entity.StringEntity entity)
Basic PUT Request
|
void |
setCertValidationDisabled(boolean isDisabled)
Deprecated.
|
void |
setConnectTimeout(long timeout)
Set's OkHttpClients Connect Timeout.
|
void |
setDefaultHeaders(Map<String,String> defaultHeaders)
Set default headers to set on all Http Requests
|
void |
setPreEmptiveBasicAuth(String targetHost,
String username,
String password)
Sets Basic Auth for all requests
|
void |
setReadTimeout(long timeout)
Set's OkHttpClients Read Timeout.
|
public static final String PUT
public static final String POST
public static final String GET
public static final String DELETE
public OkHttpTool(android.content.Context context)
context - used to install ResponseCachepublic OkHttpTool()
public com.squareup.okhttp.OkHttpClient getClient()
public void setReadTimeout(long timeout)
timeout - Time in Milliseconds to wait until Timeoutpublic void setConnectTimeout(long timeout)
timeout - Time in Milliseconds to wait until Timeoutpublic void setDefaultHeaders(Map<String,String> defaultHeaders)
defaultHeaders - Map of http headerspublic Map<String,String> getDefaultHeaders()
public HttpURLConnection get(String url) throws IOException
url - URL to send GET requestIOExceptionpublic HttpURLConnection post(String url, org.apache.http.entity.StringEntity entity) throws IOException
url - URL to send POST requestentity - StringEntity to send as the body of the POST requestIOExceptionpublic HttpURLConnection put(String url, org.apache.http.entity.StringEntity entity) throws IOException
url - URL to send PUT requestentity - StringEntity to send as the body of the PUT requestIOExceptionpublic HttpURLConnection delete(String url) throws IOException
url - URL to send DELETE requestIOException@Deprecated public void setCertValidationDisabled(boolean isDisabled)
isDisabled - public void setPreEmptiveBasicAuth(String targetHost, String username, String password)
targetHost - Host to authenticate tousername - Username of userpassword - password as userpublic BufferedReader getBufferedInputReader(HttpURLConnection connection) throws IOException
connection - HttpUrlConnection to get a reader fromIOExceptionCopyright © 2011-2014. All Rights Reserved.