Skip to content
wangchen edited this page Mar 19, 2017 · 53 revisions

####本项目的目的是学习研究并最终实现基于Retrofit OkHttp 和RxJava Gson的Android 网络请求库

  • 实现AuthToken的过期和二次自动获取机制 100%
  • 实现基础的参数的自动加入 100%
  • 实现参数的加密和签名 100%
  • 支持GET POST 以及文件传输 60%
  • 实现一个NodeJs Server 模拟真实的服务器 100%
  • 方便的支持Mock 40%
  • 支持自定义Cache 100%

###URL Connection和 OkHttp 之间的关系

    /**
     * Sets the stream handler factory for this VM.
     *
     * @throws Error if a URLStreamHandlerFactory has already been installed
     *     for the current VM.
     */
    public static synchronized void setURLStreamHandlerFactory(URLStreamHandlerFactory factory) {
        if (streamHandlerFactory != null) {
            throw new Error("Factory already set");
        }
        streamHandlers.clear();
        streamHandlerFactory = factory;
    }
    void setupStreamHandler() {
        // Check for a cached (previously looked up) handler for
        // the requested protocol.
        streamHandler = streamHandlers.get(protocol);
        if (streamHandler != null) {
            return;
        }
        if (protocol.equals("http")) {
            try {
                String name = "com.android.okhttp.HttpHandler";
                streamHandler = (URLStreamHandler) Class.forName(name).newInstance();
            } catch (Exception e) {
                throw new AssertionError(e);
            }
        } else if (protocol.equals("https")) {
            try {
                String name = "com.android.okhttp.HttpsHandler";
                streamHandler = (URLStreamHandler) Class.forName(name).newInstance();
            } catch (Exception e) {
                throw new AssertionError(e);
            }
        } else if (protocol.equals("jar")) {
            streamHandler = new JarHandler();
        }
        if (streamHandler != null) {
            streamHandlers.put(protocol, streamHandler);
        }
    }

###什么是Retrofit 它的使用方法API 简介

###内部原理

###项目代码分析

会增加多大的安装包

依赖和参考项目

  1. https://github.com/alighters/AndroidDemos
  2. npm modules express body-parser

参考文献 http://expressjs.com/ https://github.com/alighters/AndroidDemos

Clone this wiki locally