Android 异步 HTTP 库 android-async-http-cached

码农软件 · 软件分类 · 网络工具包 · 2019-02-26 12:13:32

软件介绍

android-async-http (android-async-http-cached)是基于 Android Asynchronous HTTP Library (https://github.com/loopj/android-async-http)  实现。

1.增加响应数据本地缓存功能。
2.便于JSON-RPC,XML-RPC方式调用。  

用法:

public class TestActivity extends Activity {

    private static final int REQUEST_GET_ID = 0;
    private static final int REQUEST_POST_ID = 1;
    private static final int REQUEST_POST_JSON_ID = 2;
    private static final int REQUEST_POST_XML_ID = 3;

    private RequestManager mRequestManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.mRequestManager = RequestManager
                .getInstance(getApplicationContext());

        get();
        postParams();
        postJSONObject();
        postXML();
    }

    /**
     * get by url
     */
    private void get() {
        this.mRequestManager
                .get("http://app.shafa.com/api/push/download/52a093cf3bf55d361e000477?response-content-type=application%2fvnd.android.package-archive",
                        null, requestListener, true, REQUEST_GET_ID);
    }

    /**
     * post by RequestParams
     */
    private void postParams() {
        final RequestParams params = new RequestParams();
        params.put("key1", "value1");
        params.put("key2", "value2");
        this.mRequestManager.post("http://server.winfirm.net/memoServer",
                params, requestListener, REQUEST_POST_ID);
    }

    /**
     * post by JSONObject
     */
    private void postJSONObject() {
        final JSONObject json = new JSONObject();
        try {
            json.put("key1", "value1");
            json.put("key2", "value2");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        this.mRequestManager.post("http://server.winfirm.net/memoServer", json,
                requestListener, REQUEST_POST_JSON_ID);
    }

    /**
     * post by xml
     */
    private void postXML() {
        final String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><key1>value1</key1><key2>value2</key2>";
        this.mRequestManager.post("http://server.winfirm.net/memoServer", xml,
                requestListener, REQUEST_POST_XML_ID);
    }

    /**
     * request listener
     */
    private RequestListener requestListener = new RequestListener() {
        @Override
        public void onStart() {

        }

        @Override
        public void onCompleted(int statusCode, byte[] data,
                String description, int actionId) {
            try {
                System.out.println(new String(data, "UTF-8"));
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (REQUEST_GET_ID == actionId) {
                if (RequestListener.OK == statusCode) {
                    // sucess
                } else {
                    // handler error case
                }
            } else if (REQUEST_POST_ID == actionId) {

            } else if (REQUEST_POST_JSON_ID == actionId) {

            } else if (REQUEST_POST_XML_ID == actionId) {

            }
        }

        @Override
        public void onProgress(int bytesWritten, int totalSize, int actionId) {
            System.out.println(bytesWritten + "/" + totalSize);
        }
    };

}

本文地址:https://codercto.com/soft/d/169.html

计算机网络(第7版)

计算机网络(第7版)

谢希仁 / 电子工业出版社 / 2017-1 / 45.00

本书自1989年首次出版以来,曾于1994年、1999年、2003年、2008年和2013年分别出了修订版。在2006年本书通过了教育部的评审,被纳入普通高等教育“十一五”国家级规划教材;2008年出版的第5版获得了教育部2009年精品教材称号。2013年出版的第6版是“十二五”普通高等教育本科国家级规划教材。 目前2017年发行的第7版又在第6版的基础上进行了一些修订。 全书分为9章,比较......一起来看看 《计算机网络(第7版)》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器