AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.google.com", new AsyncHttpResponseHandler() { @Override public void onStart() { // Called before a request is started } @Override public void onSuccess(int statusCode, Header[] headers, byte[] response) { // Called when response HTTP status is "200 OK" } @Override public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) { // Called when response HTTP status is "4XX" (for example, 401, 403, 404) } @Override public void onRetry(int retryNo) { // Called when request is retried } });
public class HttpUtils { private static final String BASE_URL = "http://api.twitter.com/1/"; private static AsyncHttpClient client = new AsyncHttpClient(); public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.get(getAbsoluteUrl(url), params, responseHandler); } public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.post(getAbsoluteUrl(url), params, responseHandler); } public static void getByUrl(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.get(url, params, responseHandler); } public static void postByUrl(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.post(url, params, responseHandler); } private static String getAbsoluteUrl(String relativeUrl) { return BASE_URL + relativeUrl; } }
AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.dfsdfsdfsdfsd.com", new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { // Here is your content ! } });
AsyncHttpClient client = new AsyncHttpClient(); String[] allowedContentTypes = new String[] { "image/png", "image/jpeg" }; client.get("http://example.com/file.png", new BinaryHttpResponseHandler(allowedContentTypes) { @Override public void onSuccess(byte[] fileData) { // Do something with the file } });
AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.google.com", new OWADVLHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] response) { .... } });
AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.google.com", new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { } });
public String add_guest(String name, String id, String hardware_id) { AsyncHttpClient client = new AsyncHttpClient(); String url = "http://www.mysite.com/api.php?name="+name+"&id="+id+"&hardware_id="+hardware_id; client.get(url, new JsonHttpResponseHandler()
private static AsyncHttpClient client = new AsyncHttpClient(); public static void get(String urlString, RequestParams params, AsyncHttpResponseHandler res) //url里面带参数 { client.get(urlString, params, res); }
AsyncHttpClient client = new AsyncHttpClient(); client.get("http://example.com/file.png", new FileAsyncHttpResponseHandler(/* Context */ this) { @Override public void onSuccess(int statusCode, Header[] headers, File response) { // Do something with the file `response` } });
public class SomeOtherClass { public void performSomeOtherApiCall() { AsyncHttpClient client = new AsyncHttpClient(); client.get(YourClass.URL, params, new AsyncHttpResponseHandler() { //some other code }); } }
AsyncHttpClient client = new AsyncHttpClient(); client.get("http://dev.vision-is.nl/klanten/so/content.json", new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { // Process data after request succeeded } @Override public void onFailure(Throwable arg0, String arg1) { // Print error after request failed } });
AsyncHttpClient client = new AsyncHttpClient(); String[] allowedContentTypes = new String[] { "image/png", "image/jpeg" }; client.get("http://example.com/file.png", new BinaryHttpResponseHandler(allowedContentTypes) { @Override public void onSuccess(byte[] fileData) { // Do something with the file } });
public class YourClass { public static final String URL = "http://www.example.com/abc"; public void performApiCall() { AsyncHttpClient client = new AsyncHttpClient(); client.get(URL, params, new AsyncHttpResponseHandler() { //some code }); } }
AsyncHttpClient client = new AsyncHttpClient(); client.get("https://example.com/file.png", new FileAsyncHttpResponseHandler(/* Context */ this) { @Override public void onSuccess(int statusCode, Header[] headers, File response) { // Do something with the file `response` } });
public void setImage() { if (imageUrl != null && !imageUrl.equals("null") && !imageUrl.equals("")) { AsyncHttpClient client = new AsyncHttpClient(); client.get(imageUrl, null, fileHandler); } }
String myTag = "my-long-identifier-such-as-uuid"; AsyncHttpClient ahc = new AsyncHttpClient(); RequestHandle rh = ahc.get(context, url, fileResponseHandler); rh.setTag(myTag); ahc.cancelRequestsByTAG(myTag, boolean mayInterruptIfRunning);
public class MyCLient{ private static AsyncHttpClient client = new AsyncHttpClient(); public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.get(url, params, responseHandler); } public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.post(url, params, responseHandler); }
AsyncHttpClient client = new AsyncHttpClient(); client.get("http://192.168.43.20/cgi-bin/index.cgi", new AsyncHttpResponseHandler() { dataProcessingFile secActObj = new dataProcessingFile (); //dataProcessingFile has been initialized. everything is empty in it
AsyncHttpClient ahc = new AsyncHttpClient(); ahc.get(CurrentActivity.this, url, fileResponseHandler); ahc.cancelRequests(CurrentActivity.this, boolean mayInterruptIfRunning);
import com.loopj.android.http.*; public class TwitterRestClient { private static final String BASE_URL = "http://api.twitter.com/1/"; private static AsyncHttpClient client = new AsyncHttpClient(); public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.get(getAbsoluteUrl(url), params, responseHandler); } public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.post(getAbsoluteUrl(url), params, responseHandler); } private static String getAbsoluteUrl(String relativeUrl) { return BASE_URL + relativeUrl; } }