码迷,mamicode.com
首页 > 移动开发 > 详细

android-async-http AsyncHttpClient介绍

时间:2015-08-20 14:36:32      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

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);
        }    
    }
);

以上的例子是返回的response直接是原生字节流的情况,如果你需要把返回的结果当一个String对待,这时只需要匿名实现一个
 
TextHttpResponseHandler就行,其继承自AsyncHttpResponse,并将原生的字节流根据指定的encoding转化成了string对象,
 
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);
        }    
    }
);

 

android-async-http AsyncHttpClient介绍

标签:

原文地址:http://www.cnblogs.com/zhujiabin/p/4744839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!