public abstract class TextHttpResponseHandler extends AsyncHttpResponseHandler
Additionally, you can override the { #onFailure(int, Header[], String, Throwable)}, { #onStart()}, and { #onFinish()} methods as required.
For example:
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://www.google.com", new TextHttpResponseHandler() {
@Override
public void onStart() {
// Initiated the request
}
@Override
public void onSuccess(String responseBody) {
// Successfully got a response
}
@Override
public void onFailure(String responseBody, Throwable e) {
// Response failed :(
}
@Override
public void onFinish() {
// Completed the request (either success or failure)
}
});
BUFFER_SIZE, CANCEL_MESSAGE, DEFAULT_CHARSET, FAILURE_MESSAGE, FINISH_MESSAGE, PROGRESS_MESSAGE, RETRY_MESSAGE, START_MESSAGE, SUCCESS_MESSAGE, UTF8_BOM| 构造器和说明 |
|---|
TextHttpResponseHandler()
Creates new instance with default UTF-8 encoding
|
TextHttpResponseHandler(java.lang.String encoding)
Creates new instance with given string encoding
|
| 限定符和类型 | 方法和说明 |
|---|---|
static java.lang.String |
getResponseString(byte[] stringBytes,
java.lang.String charset)
Attempts to encode response bytes as string of set encoding
|
void |
onFailure(int statusCode,
Header[] headers,
byte[] responseBytes,
java.lang.Throwable throwable)
Fired when a request fails to complete, override to handle in your own code
|
abstract void |
onFailure(int statusCode,
Header[] headers,
java.lang.String responseString,
java.lang.Throwable throwable)
Called when request fails
|
void |
onSuccess(int statusCode,
Header[] headers,
byte[] responseBytes)
Fired when a request returns successfully, override to handle in your own code
|
abstract void |
onSuccess(int statusCode,
Header[] headers,
java.lang.String responseString)
Called when request succeeds
|
getCharset, getRequestHeaders, getRequestURI, getUsePoolThread, getUseSynchronousMode, handleMessage, obtainMessage, onCancel, onFinish, onPostProcessResponse, onPreProcessResponse, onProgress, onRetry, onStart, onUserException, postRunnable, sendCancelMessage, sendFailureMessage, sendFinishMessage, sendMessage, sendProgressMessage, sendResponseMessage, sendRetryMessage, sendStartMessage, sendSuccessMessage, setCharset, setRequestHeaders, setRequestURI, setUsePoolThread, setUseSynchronousModepublic TextHttpResponseHandler()
public TextHttpResponseHandler(java.lang.String encoding)
encoding - String encoding, see AsyncHttpResponseHandler.setCharset(String)public abstract void onFailure(int statusCode,
Header[] headers,
java.lang.String responseString,
java.lang.Throwable throwable)
statusCode - http response status lineheaders - response headers if anyresponseString - string response of given charsetthrowable - throwable returned when processing requestpublic abstract void onSuccess(int statusCode,
Header[] headers,
java.lang.String responseString)
statusCode - http response status lineheaders - response headers if anyresponseString - string response of given charsetpublic void onSuccess(int statusCode,
Header[] headers,
byte[] responseBytes)
AsyncHttpResponseHandleronSuccess 在类中 AsyncHttpResponseHandlerstatusCode - the status code of the responseheaders - return headers, if anyresponseBytes - the body of the HTTP response from the serverpublic void onFailure(int statusCode,
Header[] headers,
byte[] responseBytes,
java.lang.Throwable throwable)
AsyncHttpResponseHandleronFailure 在类中 AsyncHttpResponseHandlerstatusCode - return HTTP status codeheaders - return headers, if anyresponseBytes - the response body, if anythrowable - the underlying cause of the failurepublic static java.lang.String getResponseString(byte[] stringBytes,
java.lang.String charset)
charset - charset to create string withstringBytes - response bytes