okhttp是非常强大的网络请求数据,大家也都有了解了,废话不多说,直接上代码,一种特别简单的封装。
第一步:
导包:
compile 'com.zhy:okhttputils:2.0.0'
compile 'com.google.code.gson:gson:2.8.2'
第二步:
创建net包,在这个包中只需三个类(Api,OkHttp,OnNetListener)
Api用来写接口
public static boolean isOnline = false; public static final String PRODUCT = "http://www.baidu.com"; public static final String DEVELOP = "http://169.254.209.91"; public static final String HOST = isOnline ? PRODUCT : DEVELOP; public static final String MAIN_PAGE