Android网络请求框架AsyncHttpClient详解

AsyncHttpClient框架下载地址:http://loopj.com/android-async-http/

使用如下,需要使用jar包,

import com.loopj.android.http.*;  
private final String sinaGPS = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json";
AsyncHttpClient httpClient = new AsyncHttpClient();
httpClient.get(sinaGPS, new AsyncHttpResponseHandler() {
    @Override
    public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
        if(arg2 == null ) {
            return ;
        }
        try {
            JSONUtils.getString(new String(arg2), "city", "")
        }catch (Exception e) {
            Log.e(TAG, "getWeatherInfo: " + e );
        }
    }

    @Override
    public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
        Log.e(TAG, "get_City_Error: " + arg3.toString());
    }
});

在app/build.grade添加导入jar

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    implementation files('libs/android-async-http-1.4.6.jar')
}
Volley框架已经在API 9之后抛弃了HttpClient,为什么现在这个框架用的还这么多呢?有没有什么道理?

猜你喜欢

转载自blog.csdn.net/wd229047557/article/details/80743367