Bootstrap

Android Okhttp工具类

public class OkHttpManager {
    private static OkHttpClient mOkHttpClient;
    private static volatile OkHttpManager instance = null;
    private OkHttpManager() {
    }
    public static OkHttpManager getInstance() {
        if (mOkHttpClient == null) {
            if (instance == null) {
                synchronized (OkHttpManager.class) {
                    if (mOkHttpClient == null)
                        mOkHttpClient = new OkHttpClient();
                    if (instance == null)
                        instance = new OkHttpManager();
                    initOkHttpClient();
                }
            }
        }
        return instance;
    }
    /**
     * 设置请求超时时间以及缓存
     */
    private static void initOkHttpClient() {
        //设置缓存目录
        File sdcache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/cache");
        //设置缓存大小,10MB
        int cacheSize = 1024 * 1024 * 10;
        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                //连接超时时间 10S
                .connectTimeout(10, TimeUnit.SECONDS)
                //写入超时时间 20S
                .writeTimeout(20, TimeUnit.SECONDS)
                //读取超时时间 20S
                .readTimeout(20, TimeUnit.SECONDS)
                //缓存
                .cache(new Cache(sdcache.getAbsoluteFile(), cacheSize));
        //将请求设置参数赋值给OkHttp对象
        mOkHttpClient = builder.build();
    }
    /**
     * get异步请求
     *
     * @param what         唯一识别码
     * @param httpCallBack 回调
     * @param httpUrl      请求地址
     */
    publi

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;