public class AsyncHttpClient
extends java.lang.Object
RequestParams instance, and responses can be handled by passing an anonymously overridden ResponseHandlerInterface instance. For example:
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://www.google.com", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
System.out.println(response);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable
error)
{
error.printStackTrace(System.out);
}
});
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_MAX_CONNECTIONS |
static int |
DEFAULT_MAX_RETRIES |
static int |
DEFAULT_RETRY_SLEEP_TIME_MILLIS |
static int |
DEFAULT_SOCKET_BUFFER_SIZE |
static int |
DEFAULT_SOCKET_TIMEOUT |
static java.lang.String |
ENCODING_GZIP |
static java.lang.String |
HEADER_ACCEPT_ENCODING |
static java.lang.String |
HEADER_CONTENT_DISPOSITION |
static java.lang.String |
HEADER_CONTENT_ENCODING |
static java.lang.String |
HEADER_CONTENT_RANGE |
static java.lang.String |
HEADER_CONTENT_TYPE |
static java.lang.String |
LOG_TAG |
| 构造器和说明 |
|---|
AsyncHttpClient()
Creates a new AsyncHttpClient with default constructor arguments values
|
AsyncHttpClient(boolean fixNoHttpResponseException,
int httpPort,
int httpsPort)
Creates new AsyncHttpClient using given params
|
AsyncHttpClient(int httpPort)
Creates a new AsyncHttpClient.
|
AsyncHttpClient(int httpPort,
int httpsPort)
Creates a new AsyncHttpClient.
|
AsyncHttpClient(SchemeRegistry schemeRegistry)
Creates a new AsyncHttpClient.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addHeader(java.lang.String header,
java.lang.String value)
Sets headers that will be added to all requests this client makes (before sending).
|
static void |
allowRetryExceptionClass(java.lang.Class<?> cls) |
static void |
blockRetryExceptionClass(java.lang.Class<?> cls) |
void |
cancelAllRequests(boolean mayInterruptIfRunning)
Cancels all pending (or potentially active) requests.
|
void |
cancelRequests(android.content.Context context,
boolean mayInterruptIfRunning)
Cancels any pending (or potentially active) requests associated with the passed Context.
|
void |
clearBasicAuth()
已过时。
|
void |
clearCredentialsProvider()
Removes previously set auth credentials
|
protected ClientConnectionManager |
createConnectionManager(SchemeRegistry schemeRegistry,
BasicHttpParams httpParams)
Provided so it is easier for developers to provide custom ThreadSafeClientConnManager implementation
|
RequestHandle |
delete(android.content.Context context,
java.lang.String url,
Header[] headers,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP DELETE request.
|
RequestHandle |
delete(android.content.Context context,
java.lang.String url,
Header[] headers,
ResponseHandlerInterface responseHandler)
Perform a HTTP DELETE request.
|
RequestHandle |
delete(android.content.Context context,
java.lang.String url,
HttpEntity entity,
java.lang.String contentType,
ResponseHandlerInterface responseHandler)
Perform a HTTP DELETE request and track the Android Context which initiated the request.
|
RequestHandle |
delete(android.content.Context context,
java.lang.String url,
ResponseHandlerInterface responseHandler)
Perform a HTTP DELETE request.
|
void |
delete(java.lang.String url,
RequestParams params,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP DELETE request.
|
RequestHandle |
delete(java.lang.String url,
ResponseHandlerInterface responseHandler)
Perform a HTTP DELETE request.
|
static void |
endEntityViaReflection(HttpEntity entity)
This horrible hack is required on Android, due to implementation of BasicManagedEntity, which
doesn't chain call consumeContent on underlying wrapped HttpEntity
|
RequestHandle |
get(android.content.Context context,
java.lang.String url,
Header[] headers,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP GET request and track the Android Context which initiated the request with
customized headers
|
RequestHandle |
get(android.content.Context context,
java.lang.String url,
HttpEntity entity,
java.lang.String contentType,
ResponseHandlerInterface responseHandler)
Perform a HTTP GET request and track the Android Context which initiated the request.
|
RequestHandle |
get(android.content.Context context,
java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP GET request and track the Android Context which initiated the request.
|
RequestHandle |
get(android.content.Context context,
java.lang.String url,
ResponseHandlerInterface responseHandler)
Perform a HTTP GET request without any parameters and track the Android Context which
initiated the request.
|
RequestHandle |
get(java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP GET request with parameters.
|
RequestHandle |
get(java.lang.String url,
ResponseHandlerInterface responseHandler)
Perform a HTTP GET request, without any parameters.
|
int |
getConnectTimeout()
Returns current connection timeout limit (milliseconds).
|
protected java.util.concurrent.ExecutorService |
getDefaultThreadPool()
Get the default threading pool to be used for this HTTP client.
|
HttpClient |
getHttpClient()
Get the underlying HttpClient instance.
|
HttpContext |
getHttpContext()
Get the underlying HttpContext instance.
|
int |
getMaxConnections()
Returns current limit of parallel connections
|
int |
getResponseTimeout()
Returns current response timeout limit (milliseconds).
|
java.util.concurrent.ExecutorService |
getThreadPool()
Returns the current executor service used.
|
int |
getTimeout()
已过时。
Use either
getConnectTimeout() or getResponseTimeout() |
protected java.net.URI |
getURI(java.lang.String url)
Returns a
URI instance for the specified, absolute URL string. |
static java.lang.String |
getUrlWithQueryString(boolean shouldEncodeUrl,
java.lang.String url,
RequestParams params)
Will encode url, if not disabled, and adds params on the end of it
|
RequestHandle |
head(android.content.Context context,
java.lang.String url,
Header[] headers,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP HEAD request and track the Android Context which initiated the request with
customized headers
|
RequestHandle |
head(android.content.Context context,
java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP HEAD request and track the Android Context which initiated the request.
|
RequestHandle |
head(android.content.Context context,
java.lang.String url,
ResponseHandlerInterface responseHandler)
Perform a HTTP HEAD request without any parameters and track the Android Context which
initiated the request.
|
RequestHandle |
head(java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP HEAD request with parameters.
|
RequestHandle |
head(java.lang.String url,
ResponseHandlerInterface responseHandler)
Perform a HTTP HEAD request, without any parameters.
|
static boolean |
isInputStreamGZIPCompressed(java.io.PushbackInputStream inputStream)
Checks the InputStream if it contains GZIP compressed data
|
boolean |
isUrlEncodingEnabled() |
protected AsyncHttpRequest |
newAsyncHttpRequest(DefaultHttpClient client,
HttpContext httpContext,
HttpUriRequest uriRequest,
java.lang.String contentType,
ResponseHandlerInterface responseHandler,
android.content.Context context)
Instantiate a new asynchronous HTTP request for the passed parameters.
|
RequestHandle |
patch(android.content.Context context,
java.lang.String url,
Header[] headers,
HttpEntity entity,
java.lang.String contentType,
ResponseHandlerInterface responseHandler)
Perform a HTTP PATCH request and track the Android Context which initiated the request.
|
RequestHandle |
patch(android.content.Context context,
java.lang.String url,
HttpEntity entity,
java.lang.String contentType,
ResponseHandlerInterface responseHandler)
Perform a HTTP PATCH request and track the Android Context which initiated the request.
|
RequestHandle |
patch(android.content.Context context,
java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP PATCH request and track the Android Context which initiated the request.
|
RequestHandle |
patch(java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP PATCH request with parameters.
|
RequestHandle |
patch(java.lang.String url,
ResponseHandlerInterface responseHandler)
Perform a HTTP PATCH request, without any parameters.
|
RequestHandle |
post(android.content.Context context,
java.lang.String url,
Header[] headers,
HttpEntity entity,
java.lang.String contentType,
ResponseHandlerInterface responseHandler)
Perform a HTTP POST request and track the Android Context which initiated the request.
|
RequestHandle |
post(android.content.Context context,
java.lang.String url,
Header[] headers,
RequestParams params,
java.lang.String contentType,
ResponseHandlerInterface responseHandler)
Perform a HTTP POST request and track the Android Context which initiated the request.
|
RequestHandle |
post(android.content.Context context,
java.lang.String url,
HttpEntity entity,
java.lang.String contentType,
ResponseHandlerInterface responseHandler)
Perform a HTTP POST request and track the Android Context which initiated the request.
|
RequestHandle |
post(android.content.Context context,
java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP POST request and track the Android Context which initiated the request.
|
RequestHandle |
post(java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP POST request with parameters.
|
RequestHandle |
post(java.lang.String url,
ResponseHandlerInterface responseHandler)
Perform a HTTP POST request, without any parameters.
|
RequestHandle |
put(android.content.Context context,
java.lang.String url,
Header[] headers,
HttpEntity entity,
java.lang.String contentType,
ResponseHandlerInterface responseHandler)
Perform a HTTP PUT request and track the Android Context which initiated the request.
|
RequestHandle |
put(android.content.Context context,
java.lang.String url,
HttpEntity entity,
java.lang.String contentType,
ResponseHandlerInterface responseHandler)
Perform a HTTP PUT request and track the Android Context which initiated the request.
|
RequestHandle |
put(android.content.Context context,
java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP PUT request and track the Android Context which initiated the request.
|
RequestHandle |
put(java.lang.String url,
RequestParams params,
ResponseHandlerInterface responseHandler)
Perform a HTTP PUT request with parameters.
|
RequestHandle |
put(java.lang.String url,
ResponseHandlerInterface responseHandler)
Perform a HTTP PUT request, without any parameters.
|
void |
removeAllHeaders()
Will, before sending, remove all headers currently present in AsyncHttpClient instance, which
applies on all requests this client makes
|
void |
removeHeader(java.lang.String header)
Remove header from all requests this client makes (before sending).
|
protected RequestHandle |
sendRequest(DefaultHttpClient client,
HttpContext httpContext,
HttpUriRequest uriRequest,
java.lang.String contentType,
ResponseHandlerInterface responseHandler,
android.content.Context context)
Puts a new request in queue as a new thread in pool to be executed
|
void |
setAuthenticationPreemptive(boolean isPreemtive)
Sets HttpRequestInterceptor which handles authorization in preemtive way, as workaround you
can use call `AsyncHttpClient.addHeader("Authorization","Basic base64OfUsernameAndPassword==")`
|
void |
setBasicAuth(java.lang.String username,
java.lang.String password)
Sets basic authentication for the request.
|
void |
setBasicAuth(java.lang.String username,
java.lang.String password,
AuthScope scope)
Sets basic authentication for the request.
|
void |
setBasicAuth(java.lang.String username,
java.lang.String password,
AuthScope scope,
boolean preemtive)
Sets basic authentication for the request.
|
void |
setBasicAuth(java.lang.String username,
java.lang.String password,
boolean preemtive)
Sets basic authentication for the request.
|
void |
setConnectTimeout(int value)
Set connection timeout limit (milliseconds).
|
void |
setCookieStore(CookieStore cookieStore)
Sets an optional CookieStore to use when making requests
|
void |
setCredentials(AuthScope authScope,
Credentials credentials) |
void |
setEnableRedirects(boolean enableRedirects) |
void |
setEnableRedirects(boolean enableRedirects,
boolean enableRelativeRedirects)
Circular redirects are enabled by default
|
void |
setEnableRedirects(boolean enableRedirects,
boolean enableRelativeRedirects,
boolean enableCircularRedirects)
Simple interface method, to enable or disable redirects.
|
void |
setMaxConnections(int maxConnections)
Sets maximum limit of parallel connections
|
void |
setMaxRetriesAndTimeout(int retries,
int timeout)
Sets the maximum number of retries and timeout for a particular Request.
|
void |
setProxy(java.lang.String hostname,
int port)
Sets the Proxy by it's hostname and port
|
void |
setProxy(java.lang.String hostname,
int port,
java.lang.String username,
java.lang.String password)
Sets the Proxy by it's hostname,port,username and password
|
void |
setRedirectHandler(RedirectHandler customRedirectHandler)
Allows you to set custom RedirectHandler implementation, if the default provided doesn't suit
your needs
|
void |
setResponseTimeout(int value)
Set response timeout limit (milliseconds).
|
void |
setSSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory)
Sets the SSLSocketFactory to user when making requests.
|
void |
setThreadPool(java.util.concurrent.ExecutorService threadPool)
Overrides the threadpool implementation used when queuing/pooling requests.
|
void |
setTimeout(int value)
Set both the connection and socket timeouts.
|
void |
setURLEncodingEnabled(boolean enabled)
Sets state of URL encoding feature, see bug #227, this method allows you to turn off and on
this auto-magic feature on-demand.
|
void |
setUserAgent(java.lang.String userAgent)
Sets the User-Agent header to be sent with each request.
|
static void |
silentCloseInputStream(java.io.InputStream is)
A utility function to close an input stream without raising an exception.
|
static void |
silentCloseOutputStream(java.io.OutputStream os)
A utility function to close an output stream without raising an exception.
|
public static final java.lang.String LOG_TAG
public static final java.lang.String HEADER_CONTENT_TYPE
public static final java.lang.String HEADER_CONTENT_RANGE
public static final java.lang.String HEADER_CONTENT_ENCODING
public static final java.lang.String HEADER_CONTENT_DISPOSITION
public static final java.lang.String HEADER_ACCEPT_ENCODING
public static final java.lang.String ENCODING_GZIP
public static final int DEFAULT_MAX_CONNECTIONS
public static final int DEFAULT_SOCKET_TIMEOUT
public static final int DEFAULT_MAX_RETRIES
public static final int DEFAULT_RETRY_SLEEP_TIME_MILLIS
public static final int DEFAULT_SOCKET_BUFFER_SIZE
public AsyncHttpClient()
public AsyncHttpClient(int httpPort)
httpPort - non-standard HTTP-only portpublic AsyncHttpClient(int httpPort,
int httpsPort)
httpPort - non-standard HTTP-only porthttpsPort - non-standard HTTPS-only portpublic AsyncHttpClient(boolean fixNoHttpResponseException,
int httpPort,
int httpsPort)
fixNoHttpResponseException - Whether to fix issue or not, by omitting SSL verificationhttpPort - HTTP port to be used, must be greater than 0httpsPort - HTTPS port to be used, must be greater than 0public AsyncHttpClient(SchemeRegistry schemeRegistry)
schemeRegistry - SchemeRegistry to be usedpublic static void allowRetryExceptionClass(java.lang.Class<?> cls)
public static void blockRetryExceptionClass(java.lang.Class<?> cls)
public HttpClient getHttpClient()
public HttpContext getHttpContext()
public void setCookieStore(CookieStore cookieStore)
cookieStore - The CookieStore implementation to use, usually an instance of PersistentCookieStorepublic void setThreadPool(java.util.concurrent.ExecutorService threadPool)
threadPool - an instance of ExecutorService to use for queuing/pooling
requests.public java.util.concurrent.ExecutorService getThreadPool()
protected java.util.concurrent.ExecutorService getDefaultThreadPool()
protected ClientConnectionManager createConnectionManager(SchemeRegistry schemeRegistry,
BasicHttpParams httpParams)
schemeRegistry - SchemeRegistry, usually provided by getDefaultSchemeRegistry(boolean, int, int)httpParams - BasicHttpParamspublic void setEnableRedirects(boolean enableRedirects,
boolean enableRelativeRedirects,
boolean enableCircularRedirects)
Default setting is to disallow redirects.
enableRedirects - booleanenableRelativeRedirects - booleanenableCircularRedirects - booleanpublic void setEnableRedirects(boolean enableRedirects,
boolean enableRelativeRedirects)
enableRedirects - booleanenableRelativeRedirects - booleansetEnableRedirects(boolean, boolean, boolean)public void setEnableRedirects(boolean enableRedirects)
enableRedirects - booleansetEnableRedirects(boolean, boolean, boolean)public void setRedirectHandler(RedirectHandler customRedirectHandler)
customRedirectHandler - RedirectHandler instanceMyRedirectHandlerpublic void setUserAgent(java.lang.String userAgent)
userAgent - the string to use in the User-Agent header.public int getMaxConnections()
public void setMaxConnections(int maxConnections)
maxConnections - maximum parallel connections, must be at least 1public int getTimeout()
getConnectTimeout() or getResponseTimeout()public void setTimeout(int value)
value - the connect/socket timeout in milliseconds, at least 1 secondsetConnectTimeout(int),
setResponseTimeout(int)public int getConnectTimeout()
public void setConnectTimeout(int value)
value - Connection timeout in milliseconds, minimal value is 1000 (1 second).public int getResponseTimeout()
public void setResponseTimeout(int value)
value - Response timeout in milliseconds, minimal value is 1000 (1 second).public void setProxy(java.lang.String hostname,
int port)
hostname - the hostname (IP or DNS name)port - the port number. -1 indicates the scheme default port.public void setProxy(java.lang.String hostname,
int port,
java.lang.String username,
java.lang.String password)
hostname - the hostname (IP or DNS name)port - the port number. -1 indicates the scheme default port.username - the usernamepassword - the passwordpublic void setSSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory)
sslSocketFactory - the socket factory to use for https requests.public void setMaxRetriesAndTimeout(int retries,
int timeout)
retries - maximum number of retries per requesttimeout - sleep between retries in millisecondspublic void removeAllHeaders()
public void addHeader(java.lang.String header,
java.lang.String value)
header - the name of the headervalue - the contents of the headerpublic void removeHeader(java.lang.String header)
header - the name of the headerpublic void setBasicAuth(java.lang.String username,
java.lang.String password)
username - Basic Auth usernamepassword - Basic Auth passwordpublic void setBasicAuth(java.lang.String username,
java.lang.String password,
boolean preemtive)
username - Basic Auth usernamepassword - Basic Auth passwordpreemtive - sets authorization in preemtive mannerpublic void setBasicAuth(java.lang.String username,
java.lang.String password,
AuthScope scope)
username - Basic Auth usernamepassword - Basic Auth passwordscope - - an AuthScope objectpublic void setBasicAuth(java.lang.String username,
java.lang.String password,
AuthScope scope,
boolean preemtive)
username - Basic Auth usernamepassword - Basic Auth passwordscope - an AuthScope objectpreemtive - sets authorization in preemtive mannerpublic void setCredentials(AuthScope authScope,
Credentials credentials)
public void setAuthenticationPreemptive(boolean isPreemtive)
isPreemtive - whether the authorization is processed in preemtive way@Deprecated public void clearBasicAuth()
public void clearCredentialsProvider()
public void cancelRequests(android.content.Context context,
boolean mayInterruptIfRunning)
Note: This will only affect requests which were created with a non-null android Context. This method is intended to be used in the onDestroy method of your android activities to destroy all requests which are no longer required.
context - the android Context instance associated to the request.mayInterruptIfRunning - specifies if active requests should be cancelled along with
pending requests.public void cancelAllRequests(boolean mayInterruptIfRunning)
Note: This will only affect requests which were created with a non-null android Context. This method is intended to be used in the onDestroy method of your android activities to destroy all requests which are no longer required.
mayInterruptIfRunning - specifies if active requests should be cancelled along with
pending requests.public RequestHandle head(java.lang.String url, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle head(java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.params - additional HEAD parameters to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle head(android.content.Context context, java.lang.String url, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle head(android.content.Context context, java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.params - additional HEAD parameters to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle head(android.content.Context context, java.lang.String url, Header[] headers, RequestParams params, ResponseHandlerInterface responseHandler)
context - Context to execute request againsturl - the URL to send the request to.headers - set headers only for this requestparams - additional HEAD parameters to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle get(java.lang.String url, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle get(java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.params - additional GET parameters to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle get(android.content.Context context, java.lang.String url, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle get(android.content.Context context, java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.params - additional GET parameters to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle get(android.content.Context context, java.lang.String url, Header[] headers, RequestParams params, ResponseHandlerInterface responseHandler)
context - Context to execute request againsturl - the URL to send the request to.headers - set headers only for this requestparams - additional GET parameters to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle get(android.content.Context context, java.lang.String url, HttpEntity entity, java.lang.String contentType, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.entity - a raw { HttpEntity} to send with the request, for
example, use this to send string/json/xml payloads to a server by
passing a { org.apache.http.entity.StringEntity}.contentType - the content type of the payload you are sending, for example
application/json if sending a json payload.responseHandler - the response ha ndler instance that should handle the response.public RequestHandle post(java.lang.String url, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle post(java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.params - additional POST parameters or files to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle post(android.content.Context context, java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.params - additional POST parameters or files to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle post(android.content.Context context, java.lang.String url, HttpEntity entity, java.lang.String contentType, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.entity - a raw { HttpEntity} to send with the request, for
example, use this to send string/json/xml payloads to a server by
passing a { org.apache.http.entity.StringEntity}.contentType - the content type of the payload you are sending, for example
application/json if sending a json payload.responseHandler - the response ha ndler instance that should handle the response.public RequestHandle post(android.content.Context context, java.lang.String url, Header[] headers, RequestParams params, java.lang.String contentType, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.headers - set headers only for this requestparams - additional POST parameters to send with the request.contentType - the content type of the payload you are sending, for example
application/json if sending a json payload.responseHandler - the response handler instance that should handle the response.public RequestHandle post(android.content.Context context, java.lang.String url, Header[] headers, HttpEntity entity, java.lang.String contentType, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.headers - set headers only for this requestentity - a raw { HttpEntity} to send with the request, for example, use
this to send string/json/xml payloads to a server by passing a {
org.apache.http.entity.StringEntity}.contentType - the content type of the payload you are sending, for example
application/json if sending a json payload.responseHandler - the response handler instance that should handle the response.public RequestHandle put(java.lang.String url, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle put(java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.params - additional PUT parameters or files to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle put(android.content.Context context, java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.params - additional PUT parameters or files to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle put(android.content.Context context, java.lang.String url, HttpEntity entity, java.lang.String contentType, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.entity - a raw { HttpEntity} to send with the request, for example, use
this to send string/json/xml payloads to a server by passing a {
org.apache.http.entity.StringEntity}.contentType - the content type of the payload you are sending, for example
application/json if sending a json payload.responseHandler - the response handler instance that should handle the response.public RequestHandle put(android.content.Context context, java.lang.String url, Header[] headers, HttpEntity entity, java.lang.String contentType, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.headers - set one-time headers for this requestentity - a raw { HttpEntity} to send with the request, for example, use
this to send string/json/xml payloads to a server by passing a {
org.apache.http.entity.StringEntity}.contentType - the content type of the payload you are sending, for example
application/json if sending a json payload.responseHandler - the response handler instance that should handle the response.public RequestHandle patch(java.lang.String url, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle patch(java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.params - additional PUT parameters or files to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle patch(android.content.Context context, java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.params - additional PUT parameters or files to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle patch(android.content.Context context, java.lang.String url, HttpEntity entity, java.lang.String contentType, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle patch(android.content.Context context, java.lang.String url, Header[] headers, HttpEntity entity, java.lang.String contentType, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.headers - set one-time headers for this requestentity - a raw { HttpEntity} to send with the request, for example, use
this to send string/json/xml payloads to a server by passing a {
org.apache.http.entity.StringEntity}.contentType - the content type of the payload you are sending, for example
application/json if sending a json payload.responseHandler - the response handler instance that should handle the response.public RequestHandle delete(java.lang.String url, ResponseHandlerInterface responseHandler)
url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle delete(android.content.Context context, java.lang.String url, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.responseHandler - the response handler instance that should handle the response.public RequestHandle delete(android.content.Context context, java.lang.String url, Header[] headers, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.headers - set one-time headers for this requestresponseHandler - the response handler instance that should handle the response.public void delete(java.lang.String url,
RequestParams params,
AsyncHttpResponseHandler responseHandler)
url - the URL to send the request to.params - additional DELETE parameters or files to send with the request.responseHandler - the response handler instance that should handle the response.public RequestHandle delete(android.content.Context context, java.lang.String url, Header[] headers, RequestParams params, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.headers - set one-time headers for this requestparams - additional DELETE parameters or files to send along with requestresponseHandler - the response handler instance that should handle the response.public RequestHandle delete(android.content.Context context, java.lang.String url, HttpEntity entity, java.lang.String contentType, ResponseHandlerInterface responseHandler)
context - the Android Context which initiated the request.url - the URL to send the request to.entity - a raw {HttpEntity} to send with the request, for
example, use this to send string/json/xml payloads to a server by
passing a {org.apache.http.entity.StringEntity}.contentType - the content type of the payload you are sending, for example
application/json if sending a json payload.responseHandler - the response ha ndler instance that should handle the response.protected AsyncHttpRequest newAsyncHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, java.lang.String contentType, ResponseHandlerInterface responseHandler, android.content.Context context)
client - HttpClient to be used for request, can differ in single requestscontentType - MIME body type, for POST and PUT requests, may be nullcontext - Context of Android application, to hold the reference of requesthttpContext - HttpContext in which the request will be executedresponseHandler - ResponseHandler or its subclass to put the response intouriRequest - instance of HttpUriRequest, which means it must be of HttpDelete,
HttpPost, HttpGet, HttpPut, etc.protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, java.lang.String contentType, ResponseHandlerInterface responseHandler, android.content.Context context)
client - HttpClient to be used for request, can differ in single requestscontentType - MIME body type, for POST and PUT requests, may be nullcontext - Context of Android application, to hold the reference of requesthttpContext - HttpContext in which the request will be executedresponseHandler - ResponseHandler or its subclass to put the response intouriRequest - instance of HttpUriRequest, which means it must be of HttpDelete,
HttpPost, HttpGet, HttpPut, etc.protected java.net.URI getURI(java.lang.String url)
URI instance for the specified, absolute URL string.url - absolute URL string, containing scheme, host and pathpublic void setURLEncodingEnabled(boolean enabled)
enabled - desired state of featurepublic static java.lang.String getUrlWithQueryString(boolean shouldEncodeUrl,
java.lang.String url,
RequestParams params)
url - String with URL, should be valid URL without paramsparams - RequestParams to be appended on the end of URLshouldEncodeUrl - whether url should be encoded (replaces spaces with %20)public static boolean isInputStreamGZIPCompressed(java.io.PushbackInputStream inputStream)
throws java.io.IOException
inputStream - InputStream to be checkedjava.io.IOExceptionpublic static void silentCloseInputStream(java.io.InputStream is)
is - input stream to close safelypublic static void silentCloseOutputStream(java.io.OutputStream os)
os - output stream to close safelypublic boolean isUrlEncodingEnabled()
public static void endEntityViaReflection(HttpEntity entity)
entity - HttpEntity, may be null