1
1
# 简单易用的网络框架
2
2
3
- > 码云地址:[ Gitee] ( https://gitee.com/getActivity/EasyHttp )
3
+ * 码云地址:[ Gitee] ( https://gitee.com/getActivity/EasyHttp )
4
4
5
- > [ 点击此处下载Demo] ( EasyHttp.apk )
5
+ * 博客地址:[ 网络请求,如斯优雅] ( https://www.jianshu.com/p/93cd59dec002 )
6
+
7
+ * [ 点击此处下载Demo] ( EasyHttp.apk )
6
8
7
9
![ ] ( EasyHttp.jpg )
8
10
9
- > 另外对 OkHttp 源码感兴趣的同学可以看下面几篇文章
11
+ * 另外对 OkHttp 原理感兴趣的同学推荐你看以下源码分析文章
10
12
11
- * [ OkHttp 精讲:拦截器执行原理] ( https://www.jianshu.com/p/e0f324fd9411 )
13
+ * [ OkHttp 精讲:拦截器执行原理] ( https://www.jianshu.com/p/e0f324fd9411 )
12
14
13
- * [ OkHttp 精讲:RetryAndFollowUpInterceptor] ( https://www.jianshu.com/p/40636d32cb67 )
15
+ * [ OkHttp 精讲:RetryAndFollowUpInterceptor] ( https://www.jianshu.com/p/40636d32cb67 )
14
16
15
- * [ OkHttp 精讲:BridgeInterceptor] ( https://www.jianshu.com/p/fab2d74de900 )
17
+ * [ OkHttp 精讲:BridgeInterceptor] ( https://www.jianshu.com/p/fab2d74de900 )
16
18
17
- * [ OkHttp 精讲:CacheInterceptor] ( https://www.jianshu.com/p/44fad764c0ae )
19
+ * [ OkHttp 精讲:CacheInterceptor] ( https://www.jianshu.com/p/44fad764c0ae )
18
20
19
- * [ OkHttp 精讲:ConnectInterceptor] ( https://www.jianshu.com/p/a3a774fdff4f )
21
+ * [ OkHttp 精讲:ConnectInterceptor] ( https://www.jianshu.com/p/a3a774fdff4f )
20
22
21
- * [ OkHttp 精讲:CallServerInterceptor] ( https://www.jianshu.com/p/aa77af6251ff )
23
+ * [ OkHttp 精讲:CallServerInterceptor] ( https://www.jianshu.com/p/aa77af6251ff )
22
24
23
25
#### Gradle 集成
24
26
@@ -33,38 +35,40 @@ android {
33
35
34
36
dependencies {
35
37
// 网络请求框架:https://github.com/getActivity/EasyHttp
36
- implementation 'com.hjq:http:8.9 '
38
+ implementation 'com.hjq:http:9.0 '
37
39
// OkHttp 框架:https://github.com/square/okhttp
38
40
// noinspection GradleDependency
39
41
implementation 'com.squareup.okhttp3:okhttp:3.12.12'
40
42
}
41
43
```
42
44
43
45
## [ 框架的具体用法请点击这里查看] ( HelpDoc.md )
44
-
45
- #### 不同网络请求框架之间的对比
46
46
47
- | 功能 | [ EasyHttp] ( https://github.com/getActivity/EasyHttp ) | [ Retrofit] ( https://github.com/square/retrofit ) | [ OkGo] ( https://github.com/jeasonlzy/okhttp-OkGo ) |
47
+ ### 不同网络请求框架之间的对比
48
+
49
+ | 功能或细节 | [ EasyHttp] ( https://github.com/getActivity/EasyHttp ) | [ Retrofit] ( https://github.com/square/retrofit ) | [ OkGo] ( https://github.com/jeasonlzy/okhttp-OkGo ) |
48
50
| :----: | :------: | :-----: | :-----: |
49
- | 对应版本 | 8.9 | 2.9.0 | 3.0.4 |
50
- | 动态 Host | 支持 | 不支持 | 支持 |
51
+ | 对应版本 | 9.0 | 2.9.0 | 3.0.4 |
52
+ | ** aar 包大小** | [ 61 KB] ( https://bintray.com/getactivity/maven/http#files/com/hjq/http ) | [ 123 KB] ( https://bintray.com/bintray/jcenter/com.squareup.retrofit2%3Aretrofit#files ) | [ 131 KB] ( https://bintray.com/jeasonlzy/maven/okgo#files/com/lzy/net/okgo ) |
53
+ | minSdk 要求 | API 14+ | API 21+ | API 14+ |
54
+ | 配置多域名 | 支持 | 不支持 | 支持 |
55
+ | ** 动态 Host** | 支持 | 不支持 | 不支持 |
51
56
| 全局参数 | 支持 | 不支持 | 支持 |
52
57
| 超时重试 | 支持 | 不支持 | 支持 |
53
- | 下载校验 | 支持 | 不支持 | 不支持 |
54
- | 极速下载 | 支持 | 不支持 | 不支持 |
55
- | 注解数量 | 3 个 | 25 个 | 0 个 |
58
+ | ** 下载校验** | 支持 | 不支持 | 不支持 |
59
+ | ** 极速下载** | 支持 | 不支持 | 不支持 |
56
60
| 上传文件类型 | File / InputStream / RequestBody | RequestBody | File |
57
61
| 批量上传文件 | 支持 | 不支持 | 支持 |
58
62
| 上传进度监听 | 支持 | 不支持 | 支持 |
59
- | Json 参数提交 | 支持 | 不支持 | 支持 |
60
- | 请求生命周期 | 自动管控 | 需要封装 | 需要封装 |
61
- | 参数传值方式 | 字段名 + 字段值 | 方法参数名 + 方法参数值 | 定义 Key + Value |
63
+ | Json 参数提交 | 支持 | 不支持 | 支持 |
64
+ | ** 请求代码定位** | 支持 | 不支持 | 不支持 |
65
+ | ** 请求生命周期** | 自动管控 | 需要封装 | 需要封装 |
66
+ | 参数传值方式 | 字段名 + 字段值 | 参数名 + 参数值 | 定义 Key + Value |
62
67
| 参数灵活性 | 不强制传入 | 强制全部传入 | 不强制传入 |
63
- | 自定义 RequestBody | 支持 | 支持 | 支持 |
64
- | minSdk 要求 | API 14+ | API 21+ | API 14+ |
65
- | class 文件数量 | 70 个 | 54 个 | 85 个 |
66
- | aar 包大小 | [ 55 KB] ( https://bintray.com/getactivity/maven/http#files/com/hjq/http ) | [ 123 KB] ( https://bintray.com/bintray/jcenter/com.squareup.retrofit2%3Aretrofit#files ) | [ 131 KB] ( https://bintray.com/jeasonlzy/maven/okgo#files/com/lzy/net/okgo ) |
67
- | 框架维护状态 | 维护中 | 维护中 | 停止维护 |
68
+ | 框架学习成本 | 中 | 高 | 低 |
69
+ | ** API 记忆成本** | 低 | 高 | 低 |
70
+ | ** 接口维护成本** | 低 | 中 | 高 |
71
+ | 框架维护状态 | 维护中 | 维护中 | 停止维护 |
68
72
69
73
* Retrofit 在我看来并不是那么好用,因为很多常用的功能实现起来比较麻烦,动态 Host 要写拦截器,日志打印要写拦截器,就连最常用的添加全局参数也要写拦截器,一个拦截器意味着要写很多代码,如果写得不够严谨还有可能出现 Bug,从而影响整个 OkHttp 请求流程,我经常在想这些功能能不能都用一句代码搞定,因为我觉得这些功能是设计框架的时候本应该考虑的,这便是我做这个框架的初心。
70
74
@@ -76,25 +80,33 @@ dependencies {
76
80
77
81
#### 极速下载功能介绍
78
82
79
- * 其实本质上面和极速秒传的原理是差不多的,只不过一个是上传,一个是下载 。而极速上传是将本地文件的 MD5 值和服务器上面的进行比对,如果服务器存在这个 MD5 值的文件,就将这份文件映射一份到这个用户的网盘上面,从而达到了极速秒传的效果。而极速下载也是同理,根据后台给的文件 MD5 值和本地文件进行对比,如果存在这个文件并且 MD5 值一致,证明这个文件和服务器上面的文件是一致的,那么就直接跳过下载,直接回调下载成功监听。
83
+ * 其实本质上面和极速秒传的原理是差不多的,只不过一个是上传,另一个是下载 。而极速上传是将本地文件的 MD5 值和服务器上面的进行比对,如果服务器存在这个 MD5 值的文件,就将这份文件映射一份到这个用户的网盘上面,从而达到了极速秒传的效果。而极速下载也是同理,根据后台给的文件 MD5 值和本地文件进行对比,如果存在这个文件并且 MD5 值一致,证明这个文件和服务器上面的文件是一致的,那么就直接跳过下载,直接回调下载成功监听。
80
84
81
- * 极速秒传和极速下载两者相同的共同点就是,利用缓存来达到极速的效果,只不过一者通过的是服务器的缓存,另一者使用的是本地的缓存,这两者都有一个共同的特点,就是减少服务器的压力,节省用户的等待时间。
85
+ * 极速秒传和极速下载两者相同的共同点就是,利用缓存来达到极速的效果,只不过一者通过的是服务器的缓存,另一者使用的是本地的缓存,这两者都有一个共同的特点,就是减少服务器的压力,节省用户的等待时间。
86
+
87
+ #### 代码定位功能介绍
88
+
89
+ * 框架会在日志打印中输出在网络请求的代码位置,这样开发者可以直接通过点击 Log 来定位代码是在哪个类哪行代码,这样可以极大提升我们排查问题的效率,特别是在请求一多且业务复杂的情况下,我相信没有一个人会拒绝这样的功能。
90
+
91
+ ![ ] ( RequestCode.png )
82
92
83
93
#### 作者的其他开源项目
84
94
85
95
* 安卓技术中台:[ AndroidProject] ( https://github.com/getActivity/AndroidProject )
86
96
87
- * 日志框架: [ Logcat ] ( https://github.com/getActivity/Logcat )
97
+ * 权限框架: [ XXPermissions ] ( https://github.com/getActivity/XXPermissions )
88
98
89
99
* 吐司框架:[ ToastUtils] ( https://github.com/getActivity/ToastUtils )
90
100
91
- * 权限框架:[ XXPermissions] ( https://github.com/getActivity/XXPermissions )
92
-
93
101
* 标题栏框架:[ TitleBar] ( https://github.com/getActivity/TitleBar )
94
102
95
103
* 国际化框架:[ MultiLanguages] ( https://github.com/getActivity/MultiLanguages )
96
104
97
- * 悬浮窗框架:[ XToast] ( https://github.com/getActivity/XToast )
105
+ * 悬浮窗框架:[ XToast] ( https://github.com/getActivity/XToast )
106
+
107
+ * 日志框架:[ Logcat] ( https://github.com/getActivity/Logcat )
108
+
109
+ * Gson 解析容错:[ GsonFactory] ( https://github.com/getActivity/GsonFactory )
98
110
99
111
#### Android技术讨论Q群:78797078
100
112
@@ -125,4 +137,5 @@ Unless required by applicable law or agreed to in writing, software
125
137
distributed under the License is distributed on an "AS IS" BASIS,
126
138
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127
139
See the License for the specific language governing permissions and
128
- limitations under the License.
140
+ limitations under the License.
141
+ ```
0 commit comments