标签:android style http os 使用 ar java for 文件
在Android开发中,发送、处理http请求简直太常见了,以至于我们的代码里到处充斥着各种HttpClient和与之相关又臭又长的代码,AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.google.com", new AsyncHttpResponseHandler() { @Override public void onStart() { // called before 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" (eg. 401, 403, 404) } @Override public void onRetry(int retryNo) { // called when request is retried } });
AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put("key", "value"); params.put("more", "data"); client.get("http://www.google.com", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] response) { System.out.println(response); } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { Log.d("ERROR", error); } } );
AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put("key", "value"); params.put("more", "data"); client.get("http://www.google.com", params, new TextHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, String response) { System.out.println(response); } @Override public void onFailure(int statusCode, Header[] headers, String responseBody, Throwable error) { Log.d("ERROR", error); } } );
String url = "https://ajax.googleapis.com/ajax/services/search/images"; AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put("q", "android"); params.put("rsz", "8"); client.get(url, params, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // Handle resulting parsed JSON response here } @Override public void onSuccess(int statusCode, Header[] headers, JSONArray response) { // Handle resulting parsed JSON response here } });
android-async-http AsyncHttpClient介绍
标签:android style http os 使用 ar java for 文件
原文地址:http://blog.csdn.net/yyt602037504/article/details/39612143