AsyHttpClient 数据交互
转自:http://loopj.com/android-async-http/doc/com/loopj/android/http/AsyncHttpClient.html
需求是用户登录后才可以获取列表
后台通过session判断用户是否登录
android端需要保持session信息
直接代码
AsyncHttpCilentUtil工具类
参考: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.ObjectThe 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 aRequestParamsinstance, and responses can be handled by passing an anonymously overriddenResponseHandlerInterfaceinstance.
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
Constructor and Description AsyncHttpClient()Creates a new AsyncHttpClient with default constructor arguments valuesAsyncHttpClient(boolean fixNoHttpResponseException, int httpPort, int httpsPort)Creates new AsyncHttpClient using given paramsAsyncHttpClient(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
Modifier and Type Method and Description voidaddHeader(java.lang.String header, java.lang.String value)Sets headers that will be added to all requests this client makes (before sending).voidcancelRequests(android.content.Context context, boolean mayInterruptIfRunning)Cancels any pending (or potentially active) requests associated with the passed Context.voidclearBasicAuth()Removes set basic auth credentialsRequestHandledelete(android.content.Context context, java.lang.String url, org.apache.http.Header[] headers, RequestParams params,ResponseHandlerInterface responseHandler)Perform a HTTP DELETE request.RequestHandledelete(android.content.Context context, java.lang.String url, org.apache.http.Header[] headers, ResponseHandlerInterface responseHandler)Perform a HTTP DELETE request.RequestHandledelete(android.content.Context context, java.lang.String url, ResponseHandlerInterface responseHandler)Perform a HTTP DELETE request.RequestHandledelete(java.lang.String url, ResponseHandlerInterface responseHandler)Perform a HTTP DELETE request.RequestHandleget(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 headersRequestHandleget(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.RequestHandleget(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.RequestHandleget(java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)Perform a HTTP GET request with parameters.RequestHandleget(java.lang.String url, ResponseHandlerInterface responseHandler)Perform a HTTP GET request, without any parameters.org.apache.http.client.HttpClientgetHttpClient()Get the underlying HttpClient instance.org.apache.http.protocol.HttpContextgetHttpContext()Get the underlying HttpContext instance.intgetMaxConnections()Returns current limit of parallel connectionsintgetTimeout()Returns current socket timeout limit (milliseconds), default is 10000 (10sec)static java.lang.StringgetUrlWithQueryString(boolean shouldEncodeUrl, java.lang.String url, RequestParams params)Will encode url, if not disabled, and adds params on the end of itRequestHandlehead(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 headersRequestHandlehead(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.RequestHandlehead(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.RequestHandlehead(java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)Perform a HTTP HEAD request with parameters.RequestHandlehead(java.lang.String url, ResponseHandlerInterface responseHandler)Perform a HTTP HEAD request, without any parameters.booleanisUrlEncodingEnabled()RequestHandlepost(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.RequestHandlepost(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.RequestHandlepost(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.RequestHandlepost(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.RequestHandlepost(java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)Perform a HTTP POST request with parameters.RequestHandlepost(java.lang.String url, ResponseHandlerInterface responseHandler)Perform a HTTP POST request, without any parameters.RequestHandleput(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.RequestHandleput(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.RequestHandleput(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.RequestHandleput(java.lang.String url, RequestParams params, ResponseHandlerInterface responseHandler)Perform a HTTP PUT request with parameters.RequestHandleput(java.lang.String url, ResponseHandlerInterface responseHandler)Perform a HTTP PUT request, without any parameters.voidremoveHeader(java.lang.String header)Remove header from all requests this client makes (before sending).protected RequestHandlesendRequest(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 executedvoidsetBasicAuth(java.lang.String username, java.lang.String password)Sets basic authentication for the request.voidsetBasicAuth(java.lang.String username, java.lang.String password, org.apache.http.auth.AuthScope scope)Sets basic authentication for the request.voidsetCookieStore(org.apache.http.client.CookieStore cookieStore)Sets an optional CookieStore to use when making requestsvoidsetEnableRedirects(boolean enableRedirects)Simple interface method, to enable or disable redirects.voidsetMaxConnections(int maxConnections)Sets maximum limit of parallel connectionsvoidsetMaxRetriesAndTimeout(int retries, int timeout)Sets the maximum number of retries and timeout for a particular Request.voidsetProxy(java.lang.String hostname, int port)Sets the Proxy by it's hostname and portvoidsetProxy(java.lang.String hostname, int port, java.lang.String username, java.lang.String password)Sets the Proxy by it's hostname,port,username and passwordvoidsetSSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory)Sets the SSLSocketFactory to user when making requests.voidsetThreadPool(java.util.concurrent.ThreadPoolExecutor threadPool)Overrides the threadpool implementation used when queuing/pooling requests.voidsetTimeout(int timeout)Set the connection and socket timeout.voidsetURLEncodingEnabled(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.voidsetUserAgent(java.lang.String userAgent)Sets the User-Agent header to be sent with each request.
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
AsyncHttpClient
public AsyncHttpClient(int httpPort, int httpsPort)
Creates a new AsyncHttpClient.- Parameters:
httpPort- non-standard HTTP-only porthttpsPort- non-standard HTTPS-only port
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 verificationhttpPort- HTTP port to be used, must be greater than 0httpsPort- 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 ofPersistentCookieStore
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 ofThreadPoolExecutorto 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
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.
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 usernamepassword- 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.
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 requesttimeout- sleep between retries in milliseconds
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 headervalue- 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
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 usernamepassword- Basic Auth password
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 usernamepassword- Basic Auth passwordscope- - an AuthScope object
clearBasicAuth
public void clearBasicAuth()
Removes set basic auth credentials
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.
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
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
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
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
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 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.- Returns:
- RequestHandle of future request process
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
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
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
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
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 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.- Returns:
- RequestHandle of future request process
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
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
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
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 rawHttpEntityto send with the request, for example, use this to send string/json/xml payloads to a server by passing aStringEntity.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
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 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.- Returns:
- RequestHandle of future request process
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 requestentity- a rawHttpEntityto send with the request, for example, use this to send string/json/xml payloads to a server by passing aStringEntity.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
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
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
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
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 rawHttpEntityto send with the request, for example, use this to send string/json/xml payloads to a server by passing aStringEntity.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
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 requestentity- a rawHttpEntityto send with the request, for example, use this to send string/json/xml payloads to a server by passing aStringEntity.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
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
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
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 requestresponseHandler- the response handler instance that should handle the response.- Returns:
- RequestHandle of future request process
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 requestparams- additional DELETE parameters or files to send along with requestresponseHandler- the response handler instance that should handle the response.- Returns:
- RequestHandle of future request process
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 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.- 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
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 paramsparams- RequestParams to be appended on the end of URLshouldEncodeUrl- whether url should be encoded (replaces spaces with %20)- Returns:
- encoded url if requested with params appended if any available
isUrlEncodingEnabled
public boolean isUrlEncodingEnabled()

浙公网安备 33010602011771号