File tree 7 files changed +32
-14
lines changed
src/main/java/com/hjq/http
7 files changed +32
-14
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ android {
33
33
34
34
dependencies {
35
35
// 网络请求框架:https://github.com/getActivity/EasyHttp
36
- implementation 'com.hjq:http:8.8 '
36
+ implementation 'com.hjq:http:8.9 '
37
37
// OkHttp 框架:https://github.com/square/okhttp
38
38
// noinspection GradleDependency
39
39
implementation 'com.squareup.okhttp3:okhttp:3.12.12'
@@ -46,7 +46,7 @@ dependencies {
46
46
47
47
| 功能 | [ EasyHttp] ( https://github.com/getActivity/EasyHttp ) | [ Retrofit] ( https://github.com/square/retrofit ) | [ OkGo] ( https://github.com/jeasonlzy/okhttp-OkGo ) |
48
48
| :----: | :------: | :-----: | :-----: |
49
- | 对应版本 | 8.8 | 2.9.0 | 3.0.4 |
49
+ | 对应版本 | 8.9 | 2.9.0 | 3.0.4 |
50
50
| 动态 Host | 支持 | 不支持 | 支持 |
51
51
| 全局参数 | 支持 | 不支持 | 支持 |
52
52
| 超时重试 | 支持 | 不支持 | 支持 |
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ android {
17
17
applicationId ' com.hjq.http.demo'
18
18
minSdkVersion 16
19
19
targetSdkVersion 30
20
- versionCode 88
21
- versionName ' 8.8 '
20
+ versionCode 89
21
+ versionName ' 8.9 '
22
22
testInstrumentationRunner ' androidx.test.runner.AndroidJUnitRunner'
23
23
}
24
24
Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ android {
12
12
13
13
defaultConfig {
14
14
minSdkVersion 14
15
- versionCode 88
16
- versionName " 8.8 "
15
+ versionCode 89
16
+ versionName " 8.9 "
17
17
}
18
18
}
19
19
@@ -30,7 +30,7 @@ publish {
30
30
userOrg = ' getactivity'
31
31
groupId = ' com.hjq'
32
32
artifactId = ' http'
33
- version = ' 8.8 '
33
+ version = ' 8.9 '
34
34
description = ' Easy-to-use network request framework'
35
35
website = " https://github.com/getActivity/EasyHttp"
36
36
}
Original file line number Diff line number Diff line change 21
21
*/
22
22
public final class JsonBody extends RequestBody {
23
23
24
- /** Json 文本数据 */
24
+ /** Json 数据 */
25
25
private final String mJson ;
26
+ /** 字节数组 */
27
+ private final byte [] mBytes ;
26
28
27
29
public JsonBody (Map map ) {
28
30
this (new JSONObject (map ));
29
31
}
30
32
31
33
public JsonBody (JSONObject jsonObject ) {
32
34
mJson = jsonObject .toString ();
35
+ mBytes = mJson .getBytes ();
33
36
}
34
37
35
38
public JsonBody (List list ) {
@@ -38,6 +41,7 @@ public JsonBody(List list) {
38
41
39
42
public JsonBody (JSONArray jsonArray ) {
40
43
mJson = jsonArray .toString ();
44
+ mBytes = mJson .getBytes ();
41
45
}
42
46
43
47
@ Override
@@ -47,13 +51,13 @@ public MediaType contentType() {
47
51
48
52
@ Override
49
53
public long contentLength () {
50
- return mJson .length ();
54
+ // 需要注意:这里需要用字节数组的长度来计算
55
+ return mBytes .length ;
51
56
}
52
57
53
58
@ Override
54
59
public void writeTo (BufferedSink sink ) throws IOException {
55
- byte [] bytes = mJson .getBytes ();
56
- sink .write (bytes , 0 , bytes .length );
60
+ sink .write (mBytes , 0 , mBytes .length );
57
61
}
58
62
59
63
@ NonNull
Original file line number Diff line number Diff line change 16
16
*/
17
17
public final class StringBody extends RequestBody {
18
18
19
+ /** 字符串数据 */
19
20
private final String mText ;
20
21
22
+ /** 字节数组 */
23
+ private final byte [] mBytes ;
24
+
21
25
public StringBody () {
22
26
this ("" );
23
27
}
24
28
25
29
public StringBody (String text ) {
26
30
mText = text ;
31
+ mBytes = mText .getBytes ();
27
32
}
28
33
29
34
@ Override
@@ -33,13 +38,13 @@ public MediaType contentType() {
33
38
34
39
@ Override
35
40
public long contentLength () {
36
- return mText .length ();
41
+ // 需要注意:这里需要用字节数组的长度来计算
42
+ return mBytes .length ;
37
43
}
38
44
39
45
@ Override
40
46
public void writeTo (BufferedSink sink ) throws IOException {
41
- byte [] bytes = mText .getBytes ();
42
- sink .write (bytes , 0 , bytes .length );
47
+ sink .write (mBytes , 0 , mBytes .length );
43
48
}
44
49
45
50
@ NonNull
Original file line number Diff line number Diff line change @@ -43,14 +43,23 @@ public BodyRequest(LifecycleOwner lifecycleOwner) {
43
43
}
44
44
45
45
public T body (Map map ) {
46
+ if (map == null ) {
47
+ return (T ) this ;
48
+ }
46
49
return body (new JsonBody (map ));
47
50
}
48
51
49
52
public T body (List list ) {
53
+ if (list == null ) {
54
+ return (T ) this ;
55
+ }
50
56
return body (new JsonBody (list ));
51
57
}
52
58
53
59
public T body (String text ) {
60
+ if (text == null ) {
61
+ return (T ) this ;
62
+ }
54
63
return body (new StringBody (text ));
55
64
}
56
65
You can’t perform that action at this time.
0 commit comments