Build 1.0_r1(from source)

android.net.http
Class AndroidHttpClient

java.lang.Object
  extended by android.net.http.AndroidHttpClient
All Implemented Interfaces:
HttpClient

public final class AndroidHttpClient
extends Object
implements HttpClient

Subclass of the Apache DefaultHttpClient that is configured with reasonable default settings and registered schemes for Android, and also lets the user add HttpRequestInterceptor classes. Don't create this directly, use the newInstance(java.lang.String) factory method.

This client processes cookies but does not retain them by default. To retain cookies, simply add a cookie store to the HttpContext:

context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);


Field Summary
static long DEFAULT_SYNC_MIN_GZIP_BYTES
           
 
Method Summary
 void close()
          Release resources associated with this client.
 void disableCurlLogging()
          Disables cURL logging for this client.
 void enableCurlLogging(String name, int level)
          Enables cURL request logging for this client.
 HttpResponse execute(HttpHost target, HttpRequest request)
          Executes a request to the target using the default context.
 HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context)
          Executes a request to the target using the given context.
<T> T
execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler)
          Executes a request to the target using the default context and processes the response using the given response handler.
<T> T
execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
          Executes a request to the target using the given context and processes the response using the given response handler.
 HttpResponse execute(HttpUriRequest request)
          Executes a request using the default context.
 HttpResponse execute(HttpUriRequest request, HttpContext context)
          Executes a request using the given context.
<T> T
execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler)
          Executes a request using the default context and processes the response using the given response handler.
<T> T
execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
          Executes a request using the given context and processes the response using the given response handler.
protected  void finalize()
          Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
static AbstractHttpEntity getCompressedEntity(byte[] data, ContentResolver resolver)
          Compress data to send to server.
 ClientConnectionManager getConnectionManager()
          Obtains the connection manager used by this client.
static long getMinGzipSize(ContentResolver resolver)
          Retrieves the minimum size for compressing data.
 HttpParams getParams()
          Obtains the parameters for this client.
static InputStream getUngzippedContent(HttpEntity entity)
          Gets the input stream from a response entity.
static void modifyRequestToAcceptGzipResponse(HttpRequest request)
          Modifies a request to indicate to the server that we would like a gzipped response.
static AndroidHttpClient newInstance(String userAgent)
          Create a new HttpClient with reasonable defaults (which you can update).
static void setThreadBlocked(boolean blocked)
          Block this thread from executing HTTP requests.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SYNC_MIN_GZIP_BYTES

public static long DEFAULT_SYNC_MIN_GZIP_BYTES
Method Detail

newInstance

public static AndroidHttpClient newInstance(String userAgent)
Create a new HttpClient with reasonable defaults (which you can update).

Parameters:
userAgent - to report in your HTTP requests.
Returns:
AndroidHttpClient for you to use for all your requests.

finalize

protected void finalize()
                 throws Throwable
Description copied from class: Object
Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Overrides:
finalize in class Object
Throws:
Throwable - The virtual machine ignores any exceptions which are thrown during finalization.

setThreadBlocked

public static void setThreadBlocked(boolean blocked)
Block this thread from executing HTTP requests. Used to guard against HTTP requests blocking the main application thread.

Parameters:
blocked - if HTTP requests run on this thread should be denied

modifyRequestToAcceptGzipResponse

public static void modifyRequestToAcceptGzipResponse(HttpRequest request)
Modifies a request to indicate to the server that we would like a gzipped response. (Uses the "Accept-Encoding" HTTP header.)

Parameters:
request - the request to modify
See Also:
getUngzippedContent(org.apache.http.HttpEntity)

getUngzippedContent

public static InputStream getUngzippedContent(HttpEntity entity)
                                       throws IOException
Gets the input stream from a response entity. If the entity is gzipped then this will get a stream over the uncompressed data.

Parameters:
entity - the entity whose content should be read
Returns:
the input stream to read from
Throws:
IOException

close

public void close()
Release resources associated with this client. You must call this, or significant resources (sockets and memory) may be leaked.


getParams

public HttpParams getParams()
Description copied from interface: HttpClient
Obtains the parameters for this client. These parameters will become defaults for all requests being executed with this client, and for the parameters of dependent objects in this client.

Specified by:
getParams in interface HttpClient
Returns:
the default parameters

getConnectionManager

public ClientConnectionManager getConnectionManager()
Description copied from interface: HttpClient
Obtains the connection manager used by this client.

Specified by:
getConnectionManager in interface HttpClient
Returns:
the connection manager

execute

public HttpResponse execute(HttpUriRequest request)
                     throws IOException
Description copied from interface: HttpClient
Executes a request using the default context.

Specified by:
execute in interface HttpClient
Parameters:
request - the request to execute
Returns:
the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.
Throws:
IOException - in case of a problem or the connection was aborted
ClientProtocolException - in case of an http protocol error

execute

public HttpResponse execute(HttpUriRequest request,
                            HttpContext context)
                     throws IOException
Description copied from interface: HttpClient
Executes a request using the given context. The route to the target will be determined by the HTTP client.

Specified by:
execute in interface HttpClient
Parameters:
request - the request to execute
context - the context to use for the execution, or null to use the default context
Returns:
the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.
Throws:
IOException - in case of a problem or the connection was aborted
ClientProtocolException - in case of an http protocol error

execute

public HttpResponse execute(HttpHost target,
                            HttpRequest request)
                     throws IOException
Description copied from interface: HttpClient
Executes a request to the target using the default context.

Specified by:
execute in interface HttpClient
Parameters:
target - the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
request - the request to execute
Returns:
the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.
Throws:
IOException - in case of a problem or the connection was aborted
ClientProtocolException - in case of an http protocol error

execute

public HttpResponse execute(HttpHost target,
                            HttpRequest request,
                            HttpContext context)
                     throws IOException
Description copied from interface: HttpClient
Executes a request to the target using the given context.

Specified by:
execute in interface HttpClient
Parameters:
target - the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
request - the request to execute
context - the context to use for the execution, or null to use the default context
Returns:
the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.
Throws:
IOException - in case of a problem or the connection was aborted
ClientProtocolException - in case of an http protocol error

execute

public <T> T execute(HttpUriRequest request,
                     ResponseHandler<? extends T> responseHandler)
          throws IOException,
                 ClientProtocolException
Description copied from interface: HttpClient
Executes a request using the default context and processes the response using the given response handler.

Specified by:
execute in interface HttpClient
Parameters:
request - the request to execute
responseHandler - the response handler
Returns:
the response object as generated by the response handler.
Throws:
IOException - in case of a problem or the connection was aborted
ClientProtocolException - in case of an http protocol error

execute

public <T> T execute(HttpUriRequest request,
                     ResponseHandler<? extends T> responseHandler,
                     HttpContext context)
          throws IOException,
                 ClientProtocolException
Description copied from interface: HttpClient
Executes a request using the given context and processes the response using the given response handler.

Specified by:
execute in interface HttpClient
Parameters:
request - the request to execute
responseHandler - the response handler
Returns:
the response object as generated by the response handler.
Throws:
IOException - in case of a problem or the connection was aborted
ClientProtocolException - in case of an http protocol error

execute

public <T> T execute(HttpHost target,
                     HttpRequest request,
                     ResponseHandler<? extends T> responseHandler)
          throws IOException,
                 ClientProtocolException
Description copied from interface: HttpClient
Executes a request to the target using the default context and processes the response using the given response handler.

Specified by:
execute in interface HttpClient
Parameters:
target - the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
request - the request to execute
responseHandler - the response handler
Returns:
the response object as generated by the response handler.
Throws:
IOException - in case of a problem or the connection was aborted
ClientProtocolException - in case of an http protocol error

execute

public <T> T execute(HttpHost target,
                     HttpRequest request,
                     ResponseHandler<? extends T> responseHandler,
                     HttpContext context)
          throws IOException,
                 ClientProtocolException
Description copied from interface: HttpClient
Executes a request to the target using the given context and processes the response using the given response handler.

Specified by:
execute in interface HttpClient
Parameters:
target - the target host for the request. Implementations may accept null if they can still determine a route, for example to a default target or by inspecting the request.
request - the request to execute
responseHandler - the response handler
context - the context to use for the execution, or null to use the default context
Returns:
the response object as generated by the response handler.
Throws:
IOException - in case of a problem or the connection was aborted
ClientProtocolException - in case of an http protocol error

getCompressedEntity

public static AbstractHttpEntity getCompressedEntity(byte[] data,
                                                     ContentResolver resolver)
                                              throws IOException
Compress data to send to server. Creates a Http Entity holding the gzipped data. The data will not be compressed if it is too short.

Parameters:
data - The bytes to compress
Returns:
Entity holding the data
Throws:
IOException

getMinGzipSize

public static long getMinGzipSize(ContentResolver resolver)
Retrieves the minimum size for compressing data. Shorter data will not be compressed.


enableCurlLogging

public void enableCurlLogging(String name,
                              int level)
Enables cURL request logging for this client.

Parameters:
name - to log messages with
level - at which to log messages (see Log)

disableCurlLogging

public void disableCurlLogging()
Disables cURL logging for this client.


Build 1.0_r1(from source)

Please submit a feedback, bug or feature