|
||||||||||
上一个类 下一个类 | 框架 无框架 | |||||||||
摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 |
java.lang.Objectcom.baidu.sapi2.http.AsyncHttpClient
public class AsyncHttpClient
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
AsyncHttpResponseHandler
instance.
For example:
AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.google.com", new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { System.out.println(response); } });
构造方法摘要 | |
---|---|
AsyncHttpClient()
Creates a new AsyncHttpClient. |
方法摘要 | |
---|---|
void |
addHeader(String header,
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 |
delete(android.content.Context context,
String url,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP DELETE request. |
void |
delete(android.content.Context context,
String url,
org.apache.http.Header[] headers,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP DELETE request. |
void |
delete(String url,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP DELETE request. |
void |
get(android.content.Context context,
String url,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP GET request without any parameters and track the Android Context which initiated the request. |
void |
get(android.content.Context context,
String url,
org.apache.http.Header[] headers,
RequestParams params,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP GET request and track the Android Context which initiated the request with customized headers |
void |
get(android.content.Context context,
String url,
RequestParams params,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP GET request and track the Android Context which initiated the request. |
void |
get(String url,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP GET request, without any parameters. |
void |
get(String url,
RequestParams params,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP GET request with parameters. |
org.apache.http.client.HttpClient |
getHttpClient()
Get the underlying HttpClient instance. |
org.apache.http.protocol.HttpContext |
getHttpContext()
Get the underlying HttpContext instance. |
static String |
getUrlWithQueryString(String url,
RequestParams params)
|
void |
post(android.content.Context context,
String url,
org.apache.http.Header[] headers,
org.apache.http.HttpEntity entity,
String contentType,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP POST request and track the Android Context which initiated the request. |
void |
post(android.content.Context context,
String url,
org.apache.http.Header[] headers,
RequestParams params,
String contentType,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP POST request and track the Android Context which initiated the request. |
void |
post(android.content.Context context,
String url,
org.apache.http.HttpEntity entity,
String contentType,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP POST request and track the Android Context which initiated the request. |
void |
post(android.content.Context context,
String url,
RequestParams params,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP POST request and track the Android Context which initiated the request. |
void |
post(String url,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP POST request, without any parameters. |
void |
post(String url,
RequestParams params,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP POST request with parameters. |
void |
put(android.content.Context context,
String url,
org.apache.http.Header[] headers,
org.apache.http.HttpEntity entity,
String contentType,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP PUT request and track the Android Context which initiated the request. |
void |
put(android.content.Context context,
String url,
org.apache.http.HttpEntity entity,
String contentType,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP PUT request and track the Android Context which initiated the request. |
void |
put(android.content.Context context,
String url,
RequestParams params,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP PUT request and track the Android Context which initiated the request. |
void |
put(String url,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP PUT request, without any parameters. |
void |
put(String url,
RequestParams params,
AsyncHttpResponseHandler responseHandler)
Perform a HTTP PUT request with parameters. |
protected void |
sendRequest(org.apache.http.impl.client.DefaultHttpClient client,
org.apache.http.protocol.HttpContext httpContext,
org.apache.http.client.methods.HttpUriRequest uriRequest,
String contentType,
AsyncHttpResponseHandler responseHandler,
android.content.Context context)
|
void |
setBasicAuth(String user,
String pass)
Sets basic authentication for the request. |
void |
setBasicAuth(String user,
String pass,
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 |
setSSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory)
Sets the SSLSocketFactory to user when making requests. |
void |
setThreadPool(ThreadPoolExecutor threadPool)
Overrides the threadpool implementation used when queuing/pooling requests. |
void |
setTimeout(int timeout)
Sets the connection time oout. |
void |
setUserAgent(String userAgent)
Sets the User-Agent header to be sent with each request. |
从类 java.lang.Object 继承的方法 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
构造方法详细信息 |
---|
public AsyncHttpClient()
方法详细信息 |
---|
public org.apache.http.client.HttpClient getHttpClient()
public org.apache.http.protocol.HttpContext getHttpContext()
public void setCookieStore(org.apache.http.client.CookieStore cookieStore)
cookieStore
- The CookieStore implementation to use, usually an
instance of PersistentCookieStore
public void setThreadPool(ThreadPoolExecutor threadPool)
threadPool
- an instance of ThreadPoolExecutor
to use for
queuing/pooling requests.public void setUserAgent(String userAgent)
userAgent
- the string to use in the User-Agent header.public void setTimeout(int timeout)
timeout
- the connect/socket timeout in millisecondspublic void setSSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory sslSocketFactory)
sslSocketFactory
- the socket factory to use for https requests.public void addHeader(String header, String value)
header
- the name of the headervalue
- the contents of the headerpublic void setBasicAuth(String user, String pass)
username
- password
- public void setBasicAuth(String user, String pass, org.apache.http.auth.AuthScope scope)
username
- password
- scope
- - an AuthScope objectpublic 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 get(String url, AsyncHttpResponseHandler responseHandler)
url
- the URL to send the request to.responseHandler
- the response handler instance that should handle
the response.public void get(String url, RequestParams params, AsyncHttpResponseHandler 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 void get(android.content.Context context, String url, AsyncHttpResponseHandler 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 void get(android.content.Context context, String url, RequestParams params, AsyncHttpResponseHandler 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 void get(android.content.Context context, String url, org.apache.http.Header[] headers, RequestParams params, AsyncHttpResponseHandler responseHandler)
url
- 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 void post(String url, AsyncHttpResponseHandler responseHandler)
url
- the URL to send the request to.responseHandler
- the response handler instance that should handle
the response.public void post(String url, RequestParams params, AsyncHttpResponseHandler 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 void post(android.content.Context context, String url, RequestParams params, AsyncHttpResponseHandler 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 void post(android.content.Context context, String url, org.apache.http.HttpEntity entity, String contentType, AsyncHttpResponseHandler 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 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 void post(android.content.Context context, String url, org.apache.http.Header[] headers, RequestParams params, String contentType, AsyncHttpResponseHandler 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 void post(android.content.Context context, String url, org.apache.http.Header[] headers, org.apache.http.HttpEntity entity, String contentType, AsyncHttpResponseHandler 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 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 void put(String url, AsyncHttpResponseHandler responseHandler)
url
- the URL to send the request to.responseHandler
- the response handler instance that should handle
the response.public void put(String url, RequestParams params, AsyncHttpResponseHandler 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 void put(android.content.Context context, String url, RequestParams params, AsyncHttpResponseHandler 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 void put(android.content.Context context, String url, org.apache.http.HttpEntity entity, String contentType, AsyncHttpResponseHandler 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 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 void put(android.content.Context context, String url, org.apache.http.Header[] headers, org.apache.http.HttpEntity entity, String contentType, AsyncHttpResponseHandler 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 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 void delete(String url, AsyncHttpResponseHandler responseHandler)
url
- the URL to send the request to.responseHandler
- the response handler instance that should handle
the response.public void delete(android.content.Context context, String url, AsyncHttpResponseHandler 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 void delete(android.content.Context context, String url, org.apache.http.Header[] headers, AsyncHttpResponseHandler 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.protected void sendRequest(org.apache.http.impl.client.DefaultHttpClient client, org.apache.http.protocol.HttpContext httpContext, org.apache.http.client.methods.HttpUriRequest uriRequest, String contentType, AsyncHttpResponseHandler responseHandler, android.content.Context context)
public static String getUrlWithQueryString(String url, RequestParams params)
|
||||||||||
上一个类 下一个类 | 框架 无框架 | |||||||||
摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 |