Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Sobot_module_Dev
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sobot_android
Sobot_module_Dev
Commits
77949842
Commit
77949842
authored
Jan 12, 2023
by
郑娜伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net 发布1.1.5 支持put
common 发布1.2.3
parent
0f4802cd
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
189 additions
and
182 deletions
+189
-182
build.gradle
sobot_common/build.gradle
+2
-2
sobot-common-publish-mavencentral.gradle
sobot_common/sobot-common-publish-mavencentral.gradle
+1
-1
sobot-network-publish-mavencentral.gradle
sobot_network/sobot-network-publish-mavencentral.gradle
+1
-1
HttpBaseUtils.java
...k/src/main/java/com/sobot/network/http/HttpBaseUtils.java
+50
-0
GetBuilder.java
.../main/java/com/sobot/network/http/builder/GetBuilder.java
+25
-31
HeadBuilder.java
...main/java/com/sobot/network/http/builder/HeadBuilder.java
+1
-1
OkHttpRequestBuilder.java
.../com/sobot/network/http/builder/OkHttpRequestBuilder.java
+6
-2
OtherRequestBuilder.java
...a/com/sobot/network/http/builder/OtherRequestBuilder.java
+19
-22
PostFileBuilder.java
.../java/com/sobot/network/http/builder/PostFileBuilder.java
+10
-19
PostFormBuilder.java
.../java/com/sobot/network/http/builder/PostFormBuilder.java
+24
-30
PostMultipartFormBuilder.java
.../sobot/network/http/builder/PostMultipartFormBuilder.java
+22
-30
PostStringBuilder.java
...ava/com/sobot/network/http/builder/PostStringBuilder.java
+10
-19
OtherRequest.java
...ain/java/com/sobot/network/http/request/OtherRequest.java
+17
-23
PostStringRequest.java
...ava/com/sobot/network/http/request/PostStringRequest.java
+1
-1
No files found.
sobot_common/build.gradle
View file @
77949842
...
...
@@ -21,12 +21,12 @@ dependencies {
// api 'com.sobot.library:utils:1.1.1'
// api 'com.sobot.library:picture:1.1.4'
// api 'com.sobot.library:net:1.1.
3
'
// api 'com.sobot.library:net:1.1.
5
'
// api 'com.sobot.library:gson:1.1.1'
// api 'com.sobot.library:utils:1.1.1'
// api 'com.sobot.library:picture_x:1.1.4'
// api 'com.sobot.library:net:1.1.
3
'
// api 'com.sobot.library:net:1.1.
5
'
// api 'com.sobot.library:gson:1.1.1'
}
...
...
sobot_common/sobot-common-publish-mavencentral.gradle
View file @
77949842
...
...
@@ -13,7 +13,7 @@ ext {
PUBLISH_GROUP_ID
=
"com.sobot.library"
//项目包名
PUBLISH_ARTIFACT_ID
=
'sobotcommon'
//项目名
// PUBLISH_ARTIFACT_ID = 'sobotcommon_x' //项目名
PUBLISH_VERSION
=
'1.2.
2
'
//版本号
PUBLISH_VERSION
=
'1.2.
3
'
//版本号
}
...
...
sobot_network/sobot-network-publish-mavencentral.gradle
View file @
77949842
...
...
@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext
{
PUBLISH_GROUP_ID
=
"com.sobot.library"
//项目包名
PUBLISH_ARTIFACT_ID
=
'net'
//项目名
PUBLISH_VERSION
=
'1.1.
3
'
//版本号
PUBLISH_VERSION
=
'1.1.
5
'
//版本号
}
...
...
sobot_network/src/main/java/com/sobot/network/http/HttpBaseUtils.java
View file @
77949842
...
...
@@ -23,6 +23,7 @@ import java.util.Map;
import
java.util.Random
;
import
okhttp3.Call
;
import
okhttp3.FormBody
;
import
okhttp3.MediaType
;
import
okhttp3.Response
;
...
...
@@ -211,6 +212,55 @@ public class HttpBaseUtils {
}
}
private
static
FormBody
addParamToBuilder
(
Map
<
String
,
String
>
params
)
{
FormBody
.
Builder
builder
=
new
FormBody
.
Builder
();
if
(
params
!=
null
&&
params
.
keySet
().
size
()
>
0
)
{
try
{
for
(
String
key
:
params
.
keySet
())
{
builder
.
add
(
key
,
params
.
get
(
key
));
}
}
catch
(
Exception
e
)
{
}
}
return
builder
.
build
();
}
public
void
doPut
(
Object
cancelTag
,
final
String
url_str
,
Map
<
String
,
String
>
paramMap
,
Map
<
String
,
String
>
headerMap
,
final
StringCallBack
callback
)
{
SobotNetLogUtils
.
i
(
"请求URL: --> "
+
url_str
);
SobotNetLogUtils
.
i
(
"请求参数: --> "
+
paramMap
);
if
(
headerMap
==
null
)
{
headerMap
=
new
HashMap
<>();
}
FormBody
formBody
=
addParamToBuilder
(
paramMap
);
SobotOkHttpUtils
.
put
()
.
requestBody
(
formBody
)
.
tag
(
cancelTag
)
.
url
(
url_str
)
.
headers
(
headerMap
)
.
build
()
.
readTimeOut
(
8
*
1000
)
.
writeTimeOut
(
8
*
1000
)
.
connTimeOut
(
8
*
1000
).
execute
(
new
StringCallback
()
{
@Override
public
void
onResponse
(
String
response
)
{
SobotNetLogUtils
.
i
(
url_str
+
"----请求返回结果: --> "
+
response
);
callback
.
onResponse
(
response
);
}
@Override
public
void
onError
(
Call
call
,
Exception
e
)
{
SobotNetLogUtils
.
i
(
call
.
toString
());
e
.
printStackTrace
();
callback
.
onError
(
e
,
call
.
toString
(),
-
1
);
}
});
}
public
void
download
(
String
url_str
,
final
File
file
,
final
FileCallBack
callback
)
{
SobotNetLogUtils
.
i
(
"下载地址:"
+
url_str
);
...
...
sobot_network/src/main/java/com/sobot/network/http/builder/GetBuilder.java
View file @
77949842
...
...
@@ -6,27 +6,23 @@ import com.sobot.network.http.request.RequestCall;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
public
class
GetBuilder
extends
OkHttpRequestBuilder
implements
HasParamsable
{
import
okhttp3.MediaType
;
public
class
GetBuilder
extends
OkHttpRequestBuilder
implements
HasParamsable
{
@Override
public
RequestCall
build
()
{
if
(
params
!=
null
)
{
public
RequestCall
build
()
{
if
(
params
!=
null
)
{
url
=
appendParams
(
url
,
params
);
}
return
new
GetRequest
(
url
,
tag
,
params
,
headers
).
build
();
}
protected
String
appendParams
(
String
url
,
Map
<
String
,
Object
>
params
)
{
protected
String
appendParams
(
String
url
,
Map
<
String
,
Object
>
params
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
url
+
"?"
);
if
(
params
!=
null
&&
!
params
.
isEmpty
())
{
for
(
String
key
:
params
.
keySet
())
{
if
(
params
!=
null
&&
!
params
.
isEmpty
())
{
for
(
String
key
:
params
.
keySet
())
{
sb
.
append
(
key
).
append
(
"="
).
append
(
params
.
get
(
key
)).
append
(
"&"
);
}
}
...
...
@@ -36,52 +32,50 @@ public class GetBuilder extends OkHttpRequestBuilder implements HasParamsable
}
@Override
public
GetBuilder
url
(
String
url
)
{
public
GetBuilder
url
(
String
url
)
{
this
.
url
=
url
;
return
this
;
}
@Override
public
GetBuilder
tag
(
Object
tag
)
{
this
.
tag
=
tag
;
public
GetBuilder
tag
(
Object
tag
)
{
this
.
tag
=
tag
;
return
this
;
}
@Override
public
GetBuilder
params
(
Map
<
String
,
Object
>
params
)
{
public
GetBuilder
params
(
Map
<
String
,
Object
>
params
)
{
this
.
params
=
params
;
return
this
;
}
@Override
public
GetBuilder
addParams
(
String
key
,
String
val
)
{
if
(
this
.
params
==
null
)
{
params
=
new
LinkedHashMap
<
String
,
Object
>();
public
GetBuilder
addParams
(
String
key
,
String
val
)
{
if
(
this
.
params
==
null
)
{
params
=
new
LinkedHashMap
<
String
,
Object
>();
}
params
.
put
(
key
,
val
);
return
this
;
}
@Override
public
GetBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
public
GetBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
this
.
headers
=
headers
;
return
this
;
}
@Override
public
GetBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
public
GetBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
}
headers
.
put
(
key
,
val
);
return
this
;
}
@Override
public
GetBuilder
mediaType
(
MediaType
mediaType
)
{
this
.
mediaType
=
mediaType
;
return
this
;
}
}
sobot_network/src/main/java/com/sobot/network/http/builder/HeadBuilder.java
View file @
77949842
...
...
@@ -9,6 +9,6 @@ public class HeadBuilder extends GetBuilder
@Override
public
RequestCall
build
()
{
return
new
OtherRequest
(
null
,
null
,
SobotOkHttpUtils
.
METHOD
.
HEAD
,
url
,
tag
,
params
,
headers
).
build
();
return
new
OtherRequest
(
null
,
mediaType
,
null
,
SobotOkHttpUtils
.
METHOD
.
HEAD
,
url
,
tag
,
params
,
headers
).
build
();
}
}
sobot_network/src/main/java/com/sobot/network/http/builder/OkHttpRequestBuilder.java
View file @
77949842
...
...
@@ -4,12 +4,14 @@ import com.sobot.network.http.request.RequestCall;
import
java.util.Map
;
public
abstract
class
OkHttpRequestBuilder
{
import
okhttp3.MediaType
;
public
abstract
class
OkHttpRequestBuilder
{
protected
String
url
;
protected
Object
tag
;
protected
Map
<
String
,
String
>
headers
;
protected
Map
<
String
,
Object
>
params
;
protected
MediaType
mediaType
;
public
abstract
OkHttpRequestBuilder
url
(
String
url
);
...
...
@@ -19,6 +21,8 @@ public abstract class OkHttpRequestBuilder
public
abstract
OkHttpRequestBuilder
addHeader
(
String
key
,
String
val
);
public
abstract
OkHttpRequestBuilder
mediaType
(
MediaType
mediaType
);
public
abstract
RequestCall
build
();
...
...
sobot_network/src/main/java/com/sobot/network/http/builder/OtherRequestBuilder.java
View file @
77949842
...
...
@@ -6,68 +6,65 @@ import com.sobot.network.http.request.RequestCall;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
okhttp3.MediaType
;
import
okhttp3.RequestBody
;
/**
* DELETE、PUT、PATCH等其他方法
*/
public
class
OtherRequestBuilder
extends
OkHttpRequestBuilder
{
public
class
OtherRequestBuilder
extends
OkHttpRequestBuilder
{
private
RequestBody
requestBody
;
private
String
method
;
private
String
content
;
private
MediaType
mediaType
;
public
OtherRequestBuilder
(
String
method
)
{
public
OtherRequestBuilder
(
String
method
)
{
this
.
method
=
method
;
}
@Override
public
RequestCall
build
()
{
return
new
OtherRequest
(
requestBody
,
content
,
method
,
url
,
tag
,
params
,
headers
).
build
();
public
RequestCall
build
()
{
return
new
OtherRequest
(
requestBody
,
mediaType
,
content
,
method
,
url
,
tag
,
params
,
headers
).
build
();
}
public
OtherRequestBuilder
requestBody
(
RequestBody
requestBody
)
{
public
OtherRequestBuilder
mediaType
(
MediaType
mediaType
)
{
this
.
mediaType
=
mediaType
;
return
this
;
}
public
OtherRequestBuilder
requestBody
(
RequestBody
requestBody
)
{
this
.
requestBody
=
requestBody
;
return
this
;
}
public
OtherRequestBuilder
requestBody
(
String
content
)
{
public
OtherRequestBuilder
requestBody
(
String
content
)
{
this
.
content
=
content
;
return
this
;
}
@Override
public
OtherRequestBuilder
url
(
String
url
)
{
public
OtherRequestBuilder
url
(
String
url
)
{
this
.
url
=
url
;
return
this
;
}
@Override
public
OtherRequestBuilder
tag
(
Object
tag
)
{
public
OtherRequestBuilder
tag
(
Object
tag
)
{
this
.
tag
=
tag
;
return
this
;
}
@Override
public
OtherRequestBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
public
OtherRequestBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
this
.
headers
=
headers
;
return
this
;
}
@Override
public
OtherRequestBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
public
OtherRequestBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
}
headers
.
put
(
key
,
val
);
return
this
;
...
...
sobot_network/src/main/java/com/sobot/network/http/builder/PostFileBuilder.java
View file @
77949842
...
...
@@ -9,57 +9,48 @@ import java.util.Map;
import
okhttp3.MediaType
;
public
class
PostFileBuilder
extends
OkHttpRequestBuilder
{
public
class
PostFileBuilder
extends
OkHttpRequestBuilder
{
private
File
file
;
private
MediaType
mediaType
;
public
OkHttpRequestBuilder
file
(
File
file
)
{
public
PostFileBuilder
file
(
File
file
)
{
this
.
file
=
file
;
return
this
;
}
public
OkHttpRequestBuilder
mediaType
(
MediaType
mediaType
)
{
public
PostFileBuilder
mediaType
(
MediaType
mediaType
)
{
this
.
mediaType
=
mediaType
;
return
this
;
}
@Override
public
RequestCall
build
()
{
public
RequestCall
build
()
{
return
new
PostFileRequest
(
url
,
tag
,
params
,
headers
,
file
,
mediaType
).
build
();
}
@Override
public
PostFileBuilder
url
(
String
url
)
{
public
PostFileBuilder
url
(
String
url
)
{
this
.
url
=
url
;
return
this
;
}
@Override
public
PostFileBuilder
tag
(
Object
tag
)
{
public
PostFileBuilder
tag
(
Object
tag
)
{
this
.
tag
=
tag
;
return
this
;
}
@Override
public
PostFileBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
public
PostFileBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
this
.
headers
=
headers
;
return
this
;
}
@Override
public
PostFileBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
public
PostFileBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
}
headers
.
put
(
key
,
val
);
return
this
;
...
...
sobot_network/src/main/java/com/sobot/network/http/builder/PostFormBuilder.java
View file @
77949842
...
...
@@ -10,40 +10,36 @@ import java.util.LinkedHashMap;
import
java.util.List
;
import
java.util.Map
;
public
class
PostFormBuilder
extends
OkHttpRequestBuilder
implements
HasParamsable
{
import
okhttp3.MediaType
;
public
class
PostFormBuilder
extends
OkHttpRequestBuilder
implements
HasParamsable
{
private
List
<
FileInput
>
files
=
new
ArrayList
<
FileInput
>();
private
ProgressRequestBody
.
UploadInterceptor
uploadInterceptor
;
@Override
public
RequestCall
build
()
{
public
RequestCall
build
()
{
return
new
PostFormRequest
(
url
,
tag
,
params
,
headers
,
files
).
uploadInterceptor
(
uploadInterceptor
).
build
();
}
public
PostFormBuilder
addFile
(
String
name
,
String
filename
,
File
file
)
{
public
PostFormBuilder
addFile
(
String
name
,
String
filename
,
File
file
)
{
files
.
add
(
new
FileInput
(
name
,
filename
,
file
));
return
this
;
}
public
static
class
FileInput
{
public
static
class
FileInput
{
public
String
key
;
public
String
filename
;
public
File
file
;
public
FileInput
(
String
name
,
String
filename
,
File
file
)
{
public
FileInput
(
String
name
,
String
filename
,
File
file
)
{
this
.
key
=
name
;
this
.
filename
=
filename
;
this
.
file
=
file
;
}
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"FileInput{"
+
"key='"
+
key
+
'\''
+
", filename='"
+
filename
+
'\''
+
...
...
@@ -54,56 +50,54 @@ public class PostFormBuilder extends OkHttpRequestBuilder implements HasParamsab
//
@Override
public
PostFormBuilder
url
(
String
url
)
{
public
PostFormBuilder
url
(
String
url
)
{
this
.
url
=
url
;
return
this
;
}
@Override
public
PostFormBuilder
tag
(
Object
tag
)
{
public
PostFormBuilder
tag
(
Object
tag
)
{
this
.
tag
=
tag
;
return
this
;
}
@Override
public
PostFormBuilder
params
(
Map
<
String
,
Object
>
params
)
{
public
PostFormBuilder
params
(
Map
<
String
,
Object
>
params
)
{
this
.
params
=
params
;
return
this
;
}
@Override
public
PostFormBuilder
addParams
(
String
key
,
String
val
)
{
if
(
this
.
params
==
null
)
{
params
=
new
LinkedHashMap
<
String
,
Object
>();
public
PostFormBuilder
addParams
(
String
key
,
String
val
)
{
if
(
this
.
params
==
null
)
{
params
=
new
LinkedHashMap
<
String
,
Object
>();
}
params
.
put
(
key
,
val
);
return
this
;
}
@Override
public
PostFormBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
public
PostFormBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
this
.
headers
=
headers
;
return
this
;
}
@Override
public
PostFormBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
public
PostFormBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
}
headers
.
put
(
key
,
val
);
return
this
;
}
@Override
public
PostFormBuilder
mediaType
(
MediaType
mediaType
)
{
this
.
mediaType
=
mediaType
;
return
this
;
}
public
PostFormBuilder
uploadInterceptor
(
ProgressRequestBody
.
UploadInterceptor
uploadInterceptor
)
{
this
.
uploadInterceptor
=
uploadInterceptor
;
return
this
;
...
...
sobot_network/src/main/java/com/sobot/network/http/builder/PostMultipartFormBuilder.java
View file @
77949842
...
...
@@ -10,40 +10,36 @@ import java.util.LinkedHashMap;
import
java.util.List
;
import
java.util.Map
;
public
class
PostMultipartFormBuilder
extends
OkHttpRequestBuilder
implements
HasParamsable
{
import
okhttp3.MediaType
;
public
class
PostMultipartFormBuilder
extends
OkHttpRequestBuilder
implements
HasParamsable
{
private
List
<
FileInput
>
files
=
new
ArrayList
<
FileInput
>();
private
ProgressRequestBody
.
UploadInterceptor
uploadInterceptor
;
@Override
public
RequestCall
build
()
{
public
RequestCall
build
()
{
return
new
PostMultipartFormRequest
(
url
,
tag
,
params
,
headers
,
files
).
uploadInterceptor
(
uploadInterceptor
).
build
();
}
public
PostMultipartFormBuilder
addFile
(
String
name
,
String
filename
,
File
file
)
{
public
PostMultipartFormBuilder
addFile
(
String
name
,
String
filename
,
File
file
)
{
files
.
add
(
new
FileInput
(
name
,
filename
,
file
));
return
this
;
}
public
static
class
FileInput
{
public
static
class
FileInput
{
public
String
key
;
public
String
filename
;
public
File
file
;
public
FileInput
(
String
name
,
String
filename
,
File
file
)
{
public
FileInput
(
String
name
,
String
filename
,
File
file
)
{
this
.
key
=
name
;
this
.
filename
=
filename
;
this
.
file
=
file
;
}
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"FileInput{"
+
"key='"
+
key
+
'\''
+
", filename='"
+
filename
+
'\''
+
...
...
@@ -54,51 +50,43 @@ public class PostMultipartFormBuilder extends OkHttpRequestBuilder implements Ha
//
@Override
public
PostMultipartFormBuilder
url
(
String
url
)
{
public
PostMultipartFormBuilder
url
(
String
url
)
{
this
.
url
=
url
;
return
this
;
}
@Override
public
PostMultipartFormBuilder
tag
(
Object
tag
)
{
public
PostMultipartFormBuilder
tag
(
Object
tag
)
{
this
.
tag
=
tag
;
return
this
;
}
@Override
public
PostMultipartFormBuilder
params
(
Map
<
String
,
Object
>
params
)
{
public
PostMultipartFormBuilder
params
(
Map
<
String
,
Object
>
params
)
{
this
.
params
=
params
;
return
this
;
}
@Override
public
PostMultipartFormBuilder
addParams
(
String
key
,
String
val
)
{
if
(
this
.
params
==
null
)
{
params
=
new
LinkedHashMap
<
String
,
Object
>();
public
PostMultipartFormBuilder
addParams
(
String
key
,
String
val
)
{
if
(
this
.
params
==
null
)
{
params
=
new
LinkedHashMap
<
String
,
Object
>();
}
params
.
put
(
key
,
val
);
return
this
;
}
@Override
public
PostMultipartFormBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
public
PostMultipartFormBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
this
.
headers
=
headers
;
return
this
;
}
@Override
public
PostMultipartFormBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
public
PostMultipartFormBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
}
headers
.
put
(
key
,
val
);
return
this
;
...
...
@@ -109,5 +97,9 @@ public class PostMultipartFormBuilder extends OkHttpRequestBuilder implements Ha
return
this
;
}
public
PostMultipartFormBuilder
mediaType
(
MediaType
mediaType
)
{
this
.
mediaType
=
mediaType
;
return
this
;
}
}
sobot_network/src/main/java/com/sobot/network/http/builder/PostStringBuilder.java
View file @
77949842
...
...
@@ -8,58 +8,49 @@ import java.util.Map;
import
okhttp3.MediaType
;
public
class
PostStringBuilder
extends
OkHttpRequestBuilder
{
public
class
PostStringBuilder
extends
OkHttpRequestBuilder
{
private
String
content
;
private
MediaType
mediaType
;
public
PostStringBuilder
content
(
String
content
)
{
public
PostStringBuilder
content
(
String
content
)
{
this
.
content
=
content
;
return
this
;
}
public
PostStringBuilder
mediaType
(
MediaType
mediaType
)
{
public
PostStringBuilder
mediaType
(
MediaType
mediaType
)
{
this
.
mediaType
=
mediaType
;
return
this
;
}
@Override
public
RequestCall
build
()
{
public
RequestCall
build
()
{
return
new
PostStringRequest
(
url
,
tag
,
params
,
headers
,
content
,
mediaType
).
build
();
}
@Override
public
PostStringBuilder
url
(
String
url
)
{
public
PostStringBuilder
url
(
String
url
)
{
this
.
url
=
url
;
return
this
;
}
@Override
public
PostStringBuilder
tag
(
Object
tag
)
{
public
PostStringBuilder
tag
(
Object
tag
)
{
this
.
tag
=
tag
;
return
this
;
}
@Override
public
PostStringBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
public
PostStringBuilder
headers
(
Map
<
String
,
String
>
headers
)
{
this
.
headers
=
headers
;
return
this
;
}
@Override
public
PostStringBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
public
PostStringBuilder
addHeader
(
String
key
,
String
val
)
{
if
(
this
.
headers
==
null
)
{
headers
=
new
LinkedHashMap
<
String
,
String
>();
}
headers
.
put
(
key
,
val
);
return
this
;
...
...
sobot_network/src/main/java/com/sobot/network/http/request/OtherRequest.java
View file @
77949842
...
...
@@ -12,56 +12,50 @@ import okhttp3.Request;
import
okhttp3.RequestBody
;
import
okhttp3.internal.http.HttpMethod
;
public
class
OtherRequest
extends
OkHttpRequest
{
private
static
MediaType
MEDIA_TYPE_PLAIN
=
MediaType
.
parse
(
"text/plain;charset=utf-8"
);
public
class
OtherRequest
extends
OkHttpRequest
{
private
static
MediaType
MEDIA_TYPE_PLAIN
=
MediaType
.
parse
(
"application/json;charset=utf-8"
);
private
RequestBody
requestBody
;
private
String
method
;
private
String
content
;
private
MediaType
mediaType
;
public
OtherRequest
(
RequestBody
requestBody
,
String
content
,
String
method
,
String
url
,
Object
tag
,
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
)
{
public
OtherRequest
(
RequestBody
requestBody
,
MediaType
mediaType
,
String
content
,
String
method
,
String
url
,
Object
tag
,
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
)
{
super
(
url
,
tag
,
params
,
headers
);
this
.
requestBody
=
requestBody
;
this
.
method
=
method
;
this
.
content
=
content
;
this
.
mediaType
=
mediaType
;
if
(
this
.
mediaType
==
null
)
{
this
.
mediaType
=
MEDIA_TYPE_PLAIN
;
}
}
@Override
protected
RequestBody
buildRequestBody
()
{
if
(
requestBody
==
null
&&
TextUtils
.
isEmpty
(
content
)
&&
HttpMethod
.
requiresRequestBody
(
method
))
{
protected
RequestBody
buildRequestBody
()
{
if
(
requestBody
==
null
&&
TextUtils
.
isEmpty
(
content
)
&&
HttpMethod
.
requiresRequestBody
(
method
))
{
Exceptions
.
illegalArgument
(
"requestBody and content can not be null in method:"
+
method
);
}
if
(
requestBody
==
null
&&
!
TextUtils
.
isEmpty
(
content
))
{
requestBody
=
RequestBody
.
create
(
MEDIA_TYPE_PLAIN
,
content
);
if
(
requestBody
==
null
&&
!
TextUtils
.
isEmpty
(
content
))
{
requestBody
=
RequestBody
.
create
(
mediaType
,
content
);
}
return
requestBody
;
}
@Override
protected
Request
buildRequest
(
RequestBody
requestBody
)
{
if
(
method
.
equals
(
SobotOkHttpUtils
.
METHOD
.
PUT
))
{
protected
Request
buildRequest
(
RequestBody
requestBody
)
{
if
(
method
.
equals
(
SobotOkHttpUtils
.
METHOD
.
PUT
))
{
builder
.
put
(
requestBody
);
}
else
if
(
method
.
equals
(
SobotOkHttpUtils
.
METHOD
.
DELETE
))
{
}
else
if
(
method
.
equals
(
SobotOkHttpUtils
.
METHOD
.
DELETE
))
{
if
(
requestBody
==
null
)
builder
.
delete
();
else
builder
.
delete
(
requestBody
);
}
else
if
(
method
.
equals
(
SobotOkHttpUtils
.
METHOD
.
HEAD
))
{
}
else
if
(
method
.
equals
(
SobotOkHttpUtils
.
METHOD
.
HEAD
))
{
builder
.
head
();
}
else
if
(
method
.
equals
(
SobotOkHttpUtils
.
METHOD
.
PATCH
))
{
}
else
if
(
method
.
equals
(
SobotOkHttpUtils
.
METHOD
.
PATCH
))
{
builder
.
patch
(
requestBody
);
}
...
...
sobot_network/src/main/java/com/sobot/network/http/request/PostStringRequest.java
View file @
77949842
...
...
@@ -10,7 +10,7 @@ import okhttp3.RequestBody;
public
class
PostStringRequest
extends
OkHttpRequest
{
private
static
MediaType
MEDIA_TYPE_PLAIN
=
MediaType
.
parse
(
"
text/plai
n;charset=utf-8"
);
private
static
MediaType
MEDIA_TYPE_PLAIN
=
MediaType
.
parse
(
"
application/jso
n;charset=utf-8"
);
private
String
content
;
private
MediaType
mediaType
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment