AsyHttpClient 数据交互

转自:http://loopj.com/android-async-http/doc/com/loopj/android/http/AsyncHttpClient.html

 

需求是用户登录后才可以获取列表

 

后台通过session判断用户是否登录

android端需要保持session信息

直接代码

AsyncHttpCilentUtil工具类

[java]  view plain copy print ? 在CODE上查看代码片
  1. import android.content.Context;  
  2.   
  3. import com.loopj.android.http.AsyncHttpClient;  
  4. import com.loopj.android.http.PersistentCookieStore;  
  5.   
  6. public class AsyncHttpCilentUtil {  
  7.   
  8.     private static AsyncHttpClient client;  
  9.   
  10.     public static AsyncHttpClient getInstance(Context paramContext) {  
  11.         if (client == null) {  
  12.             client = new AsyncHttpClient();  
  13.             PersistentCookieStore myCookieStore = new PersistentCookieStore(paramContext);  
  14.             client.setCookieStore(myCookieStore);  
  15.         }  
  16.         return client;  
  17.     }  
  18. }  


参考:AsyncHttpClient的CookieStore问题

 

 

 

com.loopj.android.http

Class AsyncHttpClient

  • java.lang.Object
    • com.loopj.android.http.AsyncHttpClient
  • Direct Known Subclasses:
    SyncHttpClient


    public class AsyncHttpClient extends java.lang.Object
    The AsyncHttpClient can be used to make asynchronous GET, POST, PUT and DELETE HTTP requests in your Android applications. Requests can be made with additional parameters by passing a  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 ResponseHandlerInterface() {      @Override      public void onSuccess(String response) {          System.out.println(response);      }  });  
    • Constructor Summary

      Constructors 
      Constructor and Description
      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(org.apache.http.conn.scheme.SchemeRegistry schemeRegistry)
      Creates a new AsyncHttpClient.
    • Method Summary

      All Methods  Static Methods  Instance Methods  Concrete Methods 
      Modifier and Type Method and Description
      void addHeader(java.lang.String header, java.lang.String value)
      Sets headers that will be added to all requests this client makes (before sending).
      void cancelRequests(android.content.Context context, boolean mayInterruptIfRunning)
      Cancels any pending (or potentially active) requests associated with the passed Context.
      void clearBasicAuth()
      Removes set basic auth credentials
      RequestHandle delete(android.content.Context context, java.lang.String url, org.apache.http.Header[] headers, RequestParams params,ResponseHandlerInterface responseHandler)
      Perform a HTTP DELETE request.
      RequestHandle delete(android.content.Context context, java.lang.String url, org.apache.http.Header[] headers, ResponseHandlerInterface responseHandler)
      Perform a HTTP DELETE request.
      RequestHandle delete(android.content.Context context, java.lang.String url, ResponseHandlerInterface responseHandler)
      Perform a HTTP DELETE request.
      RequestHandle delete(java.lang.String url, ResponseHandlerInterface responseHandler)
      Perform a HTTP DELETE request.
      RequestHandle get(android.content.Context context, java.lang.String url, org.apache.http.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, 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.
      org.apache.http.client.HttpClient getHttpClient()
      Get the underlying HttpClient instance.
      org.apache.http.protocol.HttpContext getHttpContext()
      Get the underlying HttpContext instance.
      int getMaxConnections()
      Returns current limit of parallel connections
      int getTimeout()
      Returns current socket timeout limit (milliseconds), default is 10000 (10sec)
      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, org.apache.http.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.
      boolean isUrlEncodingEnabled() 
      RequestHandle post(android.content.Context context, java.lang.String url, org.apache.http.Header[] headers, org.apache.http.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, org.apache.http.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, org.apache.http.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, org.apache.http.Header[] headers, org.apache.http.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, org.apache.http.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 removeHeader(java.lang.String header)
      Remove header from all requests this client makes (before sending).
      protected RequestHandle sendRequest(org.apache.http.impl.client.DefaultHttpClient client, org.apache.http.protocol.HttpContext httpContext, org.apache.http.client.methods.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 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, org.apache.http.auth.AuthScope scope)
      Sets basic authentication for the request.
      void setCookieStore(org.apache.http.client.CookieStore cookieStore)
      Sets an optional CookieStore to use when making requests
      void setEnableRedirects(boolean enableRedirects)
      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 setSSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory)
      Sets the SSLSocketFactory to user when making requests.
      void setThreadPool(java.util.concurrent.ThreadPoolExecutor threadPool)
      Overrides the threadpool implementation used when queuing/pooling requests.
      void setTimeout(int timeout)
      Set the connection and socket timeout.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AsyncHttpClient

        public AsyncHttpClient()
        Creates a new AsyncHttpClient with default constructor arguments values
      • AsyncHttpClient

        public AsyncHttpClient(int httpPort)
        Creates a new AsyncHttpClient.
        Parameters:
        httpPort - non-standard HTTP-only port
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • AsyncHttpClient

        public AsyncHttpClient(int httpPort,                        int httpsPort)
        Creates a new AsyncHttpClient.
        Parameters:
        httpPort - non-standard HTTP-only port
        httpsPort - non-standard HTTPS-only port
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • AsyncHttpClient

        public AsyncHttpClient(boolean fixNoHttpResponseException,                        int httpPort,                        int httpsPort)
        Creates new AsyncHttpClient using given params
        Parameters:
        fixNoHttpResponseException - Whether to fix or not issue, by ommiting SSL verification
        httpPort - HTTP port to be used, must be greater than 0
        httpsPort - HTTPS port to be used, must be greater than 0
      • AsyncHttpClient

        public AsyncHttpClient(org.apache.http.conn.scheme.SchemeRegistry schemeRegistry)
        Creates a new AsyncHttpClient.
        Parameters:
        schemeRegistry - SchemeRegistry to be used
    • Method Detail

      • getHttpClient

        public org.apache.http.client.HttpClient getHttpClient()
        Get the underlying HttpClient instance. This is useful for setting additional fine-grained settings for requests by accessing the client's ConnectionManager, HttpParams and SchemeRegistry.
        Returns:
        underlying HttpClient instance
      • getHttpContext

        public org.apache.http.protocol.HttpContext getHttpContext()
        Get the underlying HttpContext instance. This is useful for getting and setting fine-grained settings for requests by accessing the context's attributes such as the CookieStore.
        Returns:
        underlying HttpContext instance
      • setCookieStore

        public void setCookieStore(org.apache.http.client.CookieStore cookieStore)
        Sets an optional CookieStore to use when making requests
        Parameters:
        cookieStore - The CookieStore implementation to use, usually an instance of  PersistentCookieStore
      • setThreadPool

        public void setThreadPool(java.util.concurrent.ThreadPoolExecutor threadPool)
        Overrides the threadpool implementation used when queuing/pooling requests. By default, Executors.newFixedThreadPool() is used.
        Parameters:
        threadPool - an instance of  ThreadPoolExecutor to use for queuing/pooling requests.
      • setEnableRedirects

        public void setEnableRedirects(boolean enableRedirects)
        Simple interface method, to enable or disable redirects. If you set manually RedirectHandler on underlying HttpClient, effects of this method will be canceled.
        Parameters:
        enableRedirects - boolean
      • setUserAgent

        public void setUserAgent(java.lang.String userAgent)
        Sets the User-Agent header to be sent with each request. By default, "Android Asynchronous Http Client/VERSION (http://loopj.com/android-async-http/)" is used.
        Parameters:
        userAgent - the string to use in the User-Agent header.
      • getMaxConnections

        public int getMaxConnections()
        Returns current limit of parallel connections
        Returns:
        maximum limit of parallel connections, default is 10
      • setMaxConnections

        public void setMaxConnections(int maxConnections)
        Sets maximum limit of parallel connections
        Parameters:
        maxConnections - maximum parallel connections, must be at least 1
      • getTimeout

        public int getTimeout()
        Returns current socket timeout limit (milliseconds), default is 10000 (10sec)
        Returns:
        Socket Timeout limit in milliseconds
      • setTimeout

        public void setTimeout(int timeout)
        Set the connection and socket timeout. By default, 10 seconds.
        Parameters:
        timeout - the connect/socket timeout in milliseconds, at least 1 second
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • setProxy

        public void setProxy(java.lang.String hostname,                      int port)
        Sets the Proxy by it's hostname and port
        Parameters:
        hostname - the hostname (IP or DNS name)
        port - the port number. -1 indicates the scheme default port.
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • setProxy

        public 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
        Parameters:
        hostname - the hostname (IP or DNS name)
        port - the port number. -1 indicates the scheme default port.
        username - the username
        password - the password
      • setSSLSocketFactory

        public void setSSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory)
        Sets the SSLSocketFactory to user when making requests. By default, a new, default SSLSocketFactory is used.
        Parameters:
        sslSocketFactory - the socket factory to use for https requests.
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • setMaxRetriesAndTimeout

        public void setMaxRetriesAndTimeout(int retries,                                     int timeout)
        Sets the maximum number of retries and timeout for a particular Request.
        Parameters:
        retries - maximum number of retries per request
        timeout - sleep between retries in milliseconds
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • addHeader

        public void addHeader(java.lang.String header,                       java.lang.String value)
        Sets headers that will be added to all requests this client makes (before sending).
        Parameters:
        header - the name of the header
        value - the contents of the header
      • removeHeader

        public void removeHeader(java.lang.String header)
        Remove header from all requests this client makes (before sending).
        Parameters:
        header - the name of the header
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • setBasicAuth

        public void setBasicAuth(java.lang.String username,                          java.lang.String password)
        Sets basic authentication for the request. Uses AuthScope.ANY. This is the same as setBasicAuth('username','password',AuthScope.ANY)
        Parameters:
        username - Basic Auth username
        password - Basic Auth password
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • setBasicAuth

        public void setBasicAuth(java.lang.String username,                          java.lang.String password,                          org.apache.http.auth.AuthScope scope)
        Sets basic authentication for the request. You should pass in your AuthScope for security. It should be like this setBasicAuth("username","password", new AuthScope("host",port,AuthScope.ANY_REALM))
        Parameters:
        username - Basic Auth username
        password - Basic Auth password
        scope - - an AuthScope object
      • clearBasicAuth

        public void clearBasicAuth()
        Removes set basic auth credentials
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • cancelRequests

        public void cancelRequests(android.content.Context context,                            boolean mayInterruptIfRunning)
        Cancels any pending (or potentially active) requests associated with the passed Context.

         

        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.
        Parameters:
        context - the android Context instance associated to the request.
        mayInterruptIfRunning - specifies if active requests should be cancelled along with pending requests.
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • head

        public RequestHandle head(java.lang.String url,                           ResponseHandlerInterface responseHandler)
        Perform a HTTP HEAD request, without any parameters.
        Parameters:
        url - the URL to send the request to.
        responseHandler - the response handler instance that should handle the response.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • head

        public RequestHandle head(java.lang.String url,                           RequestParams params,                           ResponseHandlerInterface responseHandler)
        Perform a HTTP HEAD request with parameters.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • head

        public 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.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • head

        public 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.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • head

        public RequestHandle head(android.content.Context context,                           java.lang.String url,                           org.apache.http.Header[] headers,                           RequestParams params,                           ResponseHandlerInterface responseHandler)
        Perform a HTTP HEAD request and track the Android Context which initiated the request with customized headers
        Parameters:
        context - Context to execute request against
        url - the URL to send the request to.
        headers - set headers only for this request
        params - additional HEAD parameters to send with the request.
        responseHandler - the response handler instance that should handle the response.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • get

        public RequestHandle get(java.lang.String url,                          ResponseHandlerInterface responseHandler)
        Perform a HTTP GET request, without any parameters.
        Parameters:
        url - the URL to send the request to.
        responseHandler - the response handler instance that should handle the response.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • get

        public RequestHandle get(java.lang.String url,                          RequestParams params,                          ResponseHandlerInterface responseHandler)
        Perform a HTTP GET request with parameters.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • get

        public 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.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • get

        public 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.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • get

        public RequestHandle get(android.content.Context context,                          java.lang.String url,                          org.apache.http.Header[] headers,                          RequestParams params,                          ResponseHandlerInterface responseHandler)
        Perform a HTTP GET request and track the Android Context which initiated the request with customized headers
        Parameters:
        context - Context to execute request against
        url - the URL to send the request to.
        headers - set headers only for this request
        params - additional GET parameters to send with the request.
        responseHandler - the response handler instance that should handle the response.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • post

        public RequestHandle post(java.lang.String url,                           ResponseHandlerInterface responseHandler)
        Perform a HTTP POST request, without any parameters.
        Parameters:
        url - the URL to send the request to.
        responseHandler - the response handler instance that should handle the response.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • post

        public RequestHandle post(java.lang.String url,                           RequestParams params,                           ResponseHandlerInterface responseHandler)
        Perform a HTTP POST request with parameters.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • post

        public 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.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • post

        public RequestHandle post(android.content.Context context,                           java.lang.String url,                           org.apache.http.HttpEntity entity,                           java.lang.String contentType,                           ResponseHandlerInterface responseHandler)
        Perform a HTTP POST request and track the Android Context which initiated the request.
        Parameters:
        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  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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • post

        public RequestHandle post(android.content.Context context,                           java.lang.String url,                           org.apache.http.Header[] headers,                           RequestParams params,                           java.lang.String contentType,                           ResponseHandlerInterface responseHandler)
        Perform a HTTP POST request and track the Android Context which initiated the request. Set headers only for this request
        Parameters:
        context - the Android Context which initiated the request.
        url - the URL to send the request to.
        headers - set headers only for this request
        params - 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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • post

        public RequestHandle post(android.content.Context context,                           java.lang.String url,                           org.apache.http.Header[] headers,                           org.apache.http.HttpEntity entity,                           java.lang.String contentType,                           ResponseHandlerInterface responseHandler)
        Perform a HTTP POST request and track the Android Context which initiated the request. Set headers only for this request
        Parameters:
        context - the Android Context which initiated the request.
        url - the URL to send the request to.
        headers - set headers only for this request
        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  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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • put

        public RequestHandle put(java.lang.String url,                          ResponseHandlerInterface responseHandler)
        Perform a HTTP PUT request, without any parameters.
        Parameters:
        url - the URL to send the request to.
        responseHandler - the response handler instance that should handle the response.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • put

        public RequestHandle put(java.lang.String url,                          RequestParams params,                          ResponseHandlerInterface responseHandler)
        Perform a HTTP PUT request with parameters.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • put

        public 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.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • put

        public RequestHandle put(android.content.Context context,                          java.lang.String url,                          org.apache.http.HttpEntity entity,                          java.lang.String contentType,                          ResponseHandlerInterface responseHandler)
        Perform a HTTP PUT request and track the Android Context which initiated the request. And set one-time headers for the request
        Parameters:
        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  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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • put

        public RequestHandle put(android.content.Context context,                          java.lang.String url,                          org.apache.http.Header[] headers,                          org.apache.http.HttpEntity entity,                          java.lang.String contentType,                          ResponseHandlerInterface responseHandler)
        Perform a HTTP PUT request and track the Android Context which initiated the request. And set one-time headers for the request
        Parameters:
        context - the Android Context which initiated the request.
        url - the URL to send the request to.
        headers - set one-time headers for this request
        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  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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • delete

        public RequestHandle delete(java.lang.String url,                             ResponseHandlerInterface responseHandler)
        Perform a HTTP DELETE request.
        Parameters:
        url - the URL to send the request to.
        responseHandler - the response handler instance that should handle the response.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • delete

        public RequestHandle delete(android.content.Context context,                             java.lang.String url,                             ResponseHandlerInterface responseHandler)
        Perform a HTTP DELETE request.
        Parameters:
        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.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • delete

        public RequestHandle delete(android.content.Context context,                             java.lang.String url,                             org.apache.http.Header[] headers,                             ResponseHandlerInterface responseHandler)
        Perform a HTTP DELETE request.
        Parameters:
        context - the Android Context which initiated the request.
        url - the URL to send the request to.
        headers - set one-time headers for this request
        responseHandler - the response handler instance that should handle the response.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • delete

        public RequestHandle delete(android.content.Context context,                             java.lang.String url,                             org.apache.http.Header[] headers,                             RequestParams params,                             ResponseHandlerInterface responseHandler)
        Perform a HTTP DELETE request.
        Parameters:
        context - the Android Context which initiated the request.
        url - the URL to send the request to.
        headers - set one-time headers for this request
        params - additional DELETE parameters or files to send along with request
        responseHandler - the response handler instance that should handle the response.
        Returns:
        RequestHandle of future request process
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • sendRequest

        protected RequestHandle sendRequest(org.apache.http.impl.client.DefaultHttpClient client,                                     org.apache.http.protocol.HttpContext httpContext,                                     org.apache.http.client.methods.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
        Parameters:
        client - HttpClient to be used for request, can differ in single requests
        contentType - MIME body type, for POST and PUT requests, may be null
        context - Context of Android application, to hold the reference of request
        httpContext - HttpContext in which the request will be executed
        responseHandler - ResponseHandler or its subclass to put the response into
        uriRequest - instance of HttpUriRequest, which means it must be of HttpDelete, HttpPost, HttpGet, HttpPut, etc.
        Returns:
        RequestHandle of future request process
      • setURLEncodingEnabled

        public 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.
        Parameters:
        enabled - desired state of feature
      " src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">" src="/CuteSoft_Client/CuteEditor/Images/anchor.gif">
      • getUrlWithQueryString

        public 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
        Parameters:
        url - String with URL, should be valid URL without params
        params - RequestParams to be appended on the end of URL
        shouldEncodeUrl - whether url should be encoded (replaces spaces with %20)
        Returns:
        encoded url if requested with params appended if any available
      • isUrlEncodingEnabled

        public boolean isUrlEncodingEnabled()

你可能感兴趣的:(httpclient)