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
3a45670f
Commit
3a45670f
authored
Dec 21, 2022
by
郑娜伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net android 5.0 一下手机使用HttpURLConnection 请求
发布1.1.2 net 版本
parent
b7d2f7c1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
1072 additions
and
64 deletions
+1072
-64
sobot-network-publish-mavencentral.gradle
sobot_network/sobot-network-publish-mavencentral.gradle
+1
-1
SobotHttpUtils.java
.../main/java/com/sobot/network/apiUtils/SobotHttpUtils.java
+22
-42
SobotCustomHttpUtils.java
...va/com/sobot/network/customhttp/SobotCustomHttpUtils.java
+264
-0
GlobalFied.java
...in/java/com/sobot/network/customhttp/base/GlobalFied.java
+16
-0
CommCallback.java
.../java/com/sobot/network/customhttp/bean/CommCallback.java
+11
-0
DownLoadCallBack.java
...a/com/sobot/network/customhttp/bean/DownLoadCallBack.java
+13
-0
HttpBody.java
...main/java/com/sobot/network/customhttp/bean/HttpBody.java
+123
-0
ICommCallback.java
...java/com/sobot/network/customhttp/bean/ICommCallback.java
+20
-0
StringCallBack.java
...ava/com/sobot/network/customhttp/bean/StringCallBack.java
+9
-0
UploadCallBack.java
...ava/com/sobot/network/customhttp/bean/UploadCallBack.java
+11
-0
DownLoadHttpRequester.java
...obot/network/customhttp/module/DownLoadHttpRequester.java
+90
-0
GetHttpRequester.java
...com/sobot/network/customhttp/module/GetHttpRequester.java
+80
-0
HttpRequester.java
...va/com/sobot/network/customhttp/module/HttpRequester.java
+112
-0
PostHttpRequester.java
...om/sobot/network/customhttp/module/PostHttpRequester.java
+84
-0
ProvideHttpRequester.java
...sobot/network/customhttp/module/ProvideHttpRequester.java
+20
-0
UpLoadHttpRequester.java
.../sobot/network/customhttp/module/UpLoadHttpRequester.java
+131
-0
FailedMsgUtils.java
...va/com/sobot/network/customhttp/utils/FailedMsgUtils.java
+44
-0
HttpBaseUtils.java
...k/src/main/java/com/sobot/network/http/HttpBaseUtils.java
+0
-0
GetBuilder.java
.../main/java/com/sobot/network/http/builder/GetBuilder.java
+3
-3
HasParamsable.java
...in/java/com/sobot/network/http/builder/HasParamsable.java
+1
-1
OkHttpRequestBuilder.java
.../com/sobot/network/http/builder/OkHttpRequestBuilder.java
+1
-1
PostFormBuilder.java
.../java/com/sobot/network/http/builder/PostFormBuilder.java
+2
-2
PostMultipartFormBuilder.java
.../sobot/network/http/builder/PostMultipartFormBuilder.java
+2
-2
GetRequest.java
.../main/java/com/sobot/network/http/request/GetRequest.java
+1
-1
OkHttpRequest.java
...in/java/com/sobot/network/http/request/OkHttpRequest.java
+2
-2
OtherRequest.java
...ain/java/com/sobot/network/http/request/OtherRequest.java
+1
-1
PostFileRequest.java
.../java/com/sobot/network/http/request/PostFileRequest.java
+1
-1
PostFormRequest.java
.../java/com/sobot/network/http/request/PostFormRequest.java
+3
-3
PostMultipartFormRequest.java
.../sobot/network/http/request/PostMultipartFormRequest.java
+3
-3
PostStringRequest.java
...ava/com/sobot/network/http/request/PostStringRequest.java
+1
-1
No files found.
sobot_network/sobot-network-publish-mavencentral.gradle
View file @
3a45670f
...
...
@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext
{
PUBLISH_GROUP_ID
=
"com.sobot.library"
//项目包名
PUBLISH_ARTIFACT_ID
=
'net'
//项目名
PUBLISH_VERSION
=
'1.1.
1
'
//版本号
PUBLISH_VERSION
=
'1.1.
2
'
//版本号
}
...
...
sobot_network/src/main/java/com/sobot/network/apiUtils/SobotHttpUtils.java
View file @
3a45670f
...
...
@@ -2,6 +2,7 @@ package com.sobot.network.apiUtils;
import
android.content.Context
;
import
android.os.Build
;
import
android.text.TextUtils
;
import
com.sobot.network.http.HttpBaseUtils
;
...
...
@@ -15,45 +16,39 @@ import javax.net.ssl.HostnameVerifier;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLSession
;
import
okhttp3.MediaType
;
import
okhttp3.Response
;
public
class
SobotHttpUtils
{
// ##################### 网络请求 #########################
public
static
void
doPost
(
Object
cancelTag
,
String
url
,
Map
<
String
,
String
>
paramsMap
,
public
static
void
doPost
(
Object
cancelTag
,
String
url
,
Map
<
String
,
Object
>
paramsMap
,
HttpBaseUtils
.
StringCallBack
call
)
{
HttpBaseUtils
.
getInstance
().
doPost
(
cancelTag
,
url
,
paramsMap
,
null
,
call
);
}
public
static
void
doPost
(
Object
cancelTag
,
String
url
,
Map
<
String
,
String
>
paramsMap
,
Map
<
String
,
String
>
headerMap
,
public
static
void
doPost
(
Object
cancelTag
,
String
url
,
Map
<
String
,
Object
>
paramsMap
,
Map
<
String
,
String
>
headerMap
,
HttpBaseUtils
.
StringCallBack
call
)
{
HttpBaseUtils
.
getInstance
().
doPost
(
cancelTag
,
url
,
paramsMap
,
headerMap
,
call
);
}
public
static
void
doPostByString
(
Object
cancelTag
,
String
url
,
Map
<
String
,
String
>
paramsMap
,
Map
<
String
,
String
>
headerMap
,
MediaType
mediaType
,
HttpBaseUtils
.
StringCallBack
call
)
{
HttpBaseUtils
.
getInstance
().
doPostByString
(
cancelTag
,
url
,
paramsMap
,
headerMap
,
mediaType
,
call
);
}
public
static
void
doPostByJsonString
(
Object
cancelTag
,
String
url
,
Map
<
String
,
String
>
paramsMap
,
Map
<
String
,
String
>
headerMap
,
public
static
void
doPostByJsonString
(
Object
cancelTag
,
String
url
,
Map
<
String
,
Object
>
paramsMap
,
Map
<
String
,
String
>
headerMap
,
HttpBaseUtils
.
StringCallBack
call
)
{
HttpBaseUtils
.
getInstance
().
doPostByJsonString
(
cancelTag
,
url
,
paramsMap
,
headerMap
,
call
);
}
public
static
void
doGet
(
Object
cancelTag
,
String
url
,
Map
<
String
,
String
>
paramsMap
,
public
static
void
doGet
(
Object
cancelTag
,
String
url
,
Map
<
String
,
Object
>
paramsMap
,
HttpBaseUtils
.
StringCallBack
call
)
{
HttpBaseUtils
.
getInstance
().
doGet
(
cancelTag
,
url
,
paramsMap
,
null
,
call
);
}
public
static
void
doGet
(
Object
cancelTag
,
String
url
,
Map
<
String
,
String
>
paramsMap
,
Map
<
String
,
String
>
headerMap
,
public
static
void
doGet
(
Object
cancelTag
,
String
url
,
Map
<
String
,
Object
>
paramsMap
,
Map
<
String
,
String
>
headerMap
,
HttpBaseUtils
.
StringCallBack
call
)
{
HttpBaseUtils
.
getInstance
().
doGet
(
cancelTag
,
url
,
paramsMap
,
headerMap
,
call
);
}
//同步请求
public
static
Response
doPostSync
(
Object
cancelTag
,
String
url
,
Map
<
String
,
String
>
paramsMap
,
Map
<
String
,
String
>
headerMap
)
throws
IOException
{
public
static
Response
doPostSync
(
Object
cancelTag
,
String
url
,
Map
<
String
,
Object
>
paramsMap
,
Map
<
String
,
String
>
headerMap
)
throws
IOException
{
return
HttpBaseUtils
.
getInstance
().
doPostSync
(
cancelTag
,
url
,
paramsMap
,
headerMap
);
}
...
...
@@ -66,27 +61,9 @@ public class SobotHttpUtils {
* @param filePath
* @param callBack
*/
public
static
void
uploadFile
(
Object
cancelTag
,
String
url
,
Map
<
String
,
String
>
paramsMap
,
Map
<
String
,
String
>
headerMap
,
public
static
void
uploadFile
(
Object
cancelTag
,
String
url
,
Map
<
String
,
Object
>
paramsMap
,
Map
<
String
,
String
>
headerMap
,
final
String
filePath
,
HttpBaseUtils
.
StringCallBack
callBack
)
{
///////////////////////////////////////////////////////
if
(
paramsMap
!=
null
)
{
// 基本传递参数
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"sobot---请求参数: url = "
+
url
+
", filePath="
+
filePath
+
" "
);
for
(
String
key
:
paramsMap
.
keySet
())
{
sb
.
append
(
key
+
"="
+
paramsMap
.
get
(
key
)
+
", "
);
}
SobotNetLogUtils
.
i
(
sb
.
toString
().
substring
(
0
,
sb
.
toString
().
length
()
-
2
));
}
HttpBaseUtils
.
getInstance
().
uploadFile
(
cancelTag
,
url
,
paramsMap
,
headerMap
,
filePath
,
callBack
);
}
public
interface
SobotRequestCallBack
{
void
onSuccess
(
String
result
);
void
onFailure
(
String
result
);
}
/**
...
...
@@ -102,17 +79,19 @@ public class SobotHttpUtils {
Context
applicationContext
=
context
.
getApplicationContext
();
SobotHttpGlobalContext
.
getInstance
(
applicationContext
);
}
SobotOkHttpUtils
.
getInstance
().
setHostNameVerifier
(
new
HostnameVerifier
()
{
@Override
public
boolean
verify
(
String
hostname
,
SSLSession
session
)
{
if
(!
TextUtils
.
isEmpty
(
baseUrl
)
&&
baseUrl
.
contains
(
hostname
))
{
return
true
;
}
else
{
HostnameVerifier
hv
=
HttpsURLConnection
.
getDefaultHostnameVerifier
();
boolean
verifyResult
=
hv
.
verify
(
hostname
,
session
);
return
verifyResult
;
if
(
Build
.
VERSION
.
SDK_INT
>=
21
)
{
SobotOkHttpUtils
.
getInstance
().
setHostNameVerifier
(
new
HostnameVerifier
()
{
@Override
public
boolean
verify
(
String
hostname
,
SSLSession
session
)
{
if
(!
TextUtils
.
isEmpty
(
baseUrl
)
&&
baseUrl
.
contains
(
hostname
))
{
return
true
;
}
else
{
HostnameVerifier
hv
=
HttpsURLConnection
.
getDefaultHostnameVerifier
();
boolean
verifyResult
=
hv
.
verify
(
hostname
,
session
);
return
verifyResult
;
}
}
}
}
);
}
);
}
}
}
\ No newline at end of file
sobot_network/src/main/java/com/sobot/network/customhttp/SobotCustomHttpUtils.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
;
import
com.sobot.network.customhttp.bean.CommCallback
;
import
com.sobot.network.customhttp.bean.HttpBody
;
import
com.sobot.network.customhttp.bean.ICommCallback
;
import
com.sobot.network.customhttp.module.DownLoadHttpRequester
;
import
com.sobot.network.customhttp.module.GetHttpRequester
;
import
com.sobot.network.customhttp.module.PostHttpRequester
;
import
com.sobot.network.customhttp.module.ProvideHttpRequester
;
import
com.sobot.network.customhttp.module.UpLoadHttpRequester
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.util.List
;
import
java.util.Map
;
/**
* 轻量级网络请求框架MyHttptUtils
*/
public
class
SobotCustomHttpUtils
{
private
static
final
String
TAG
=
"MyHttpUtils"
;
private
HttpBody
mHttpBody
=
new
HttpBody
();
//请求体对象
private
ICommCallback
callback
;
public
static
SobotCustomHttpUtils
build
()
{
return
new
SobotCustomHttpUtils
();
}
/**
* 构造url
*
* @param url desc
* @return this
*/
public
SobotCustomHttpUtils
url
(
String
url
)
{
mHttpBody
.
setUrl
(
url
);
return
this
;
}
/**
* 构造文件上传的url
*
* @param uploadUrl desc
* @return this
*/
public
SobotCustomHttpUtils
uploadUrl
(
String
uploadUrl
)
{
mHttpBody
.
setUploadUrl
(
uploadUrl
);
return
this
;
}
/**
* 设置读取时间超时时间,模式30s
*
* @param readTimeOut desc
* @return this
*/
public
SobotCustomHttpUtils
setReadTimeOut
(
int
readTimeOut
)
{
mHttpBody
.
setReadTimeOut
(
readTimeOut
);
return
this
;
}
/**
* 设置链接时间超时时间,模式5s
*
* @param connTimeOut desc
* @return this
*/
public
SobotCustomHttpUtils
setConnTimeOut
(
int
connTimeOut
)
{
mHttpBody
.
setConnTimeOut
(
connTimeOut
);
return
this
;
}
/**
* 设置请求体
*
* @param mHttpBody desc
* @return this
*/
public
SobotCustomHttpUtils
setHttpBody
(
HttpBody
mHttpBody
)
{
this
.
mHttpBody
=
mHttpBody
;
return
this
;
}
/**
* 获取httpbody
*
* @return this
*/
public
HttpBody
getHttpBody
()
{
return
mHttpBody
;
}
/**
* 添加参数----键值对
*
* @param key desc
* @param value desc
* @return this
*/
public
SobotCustomHttpUtils
addParam
(
String
key
,
Object
value
)
{
mHttpBody
.
addParam
(
key
,
value
);
return
this
;
}
/**
* 设置请求参数类型参数
*/
public
SobotCustomHttpUtils
setContentType
(
String
contentType
)
{
mHttpBody
.
setContentType
(
contentType
);
return
this
;
}
/**
* 设置请求参数-----按集合
*
* @param params desc
* @return this
*/
public
SobotCustomHttpUtils
addParams
(
Map
<
String
,
Object
>
params
)
{
mHttpBody
.
setParams
(
params
);
return
this
;
}
/**
* 设置请求头参数-----按集合
*
* @param headers desc
* @return this
*/
public
SobotCustomHttpUtils
addHeaders
(
Map
<
String
,
String
>
headers
)
{
mHttpBody
.
setHeaders
(
headers
);
return
this
;
}
/**
* 设置文件保存的目录
*
* @param dir desc
* @return this
*/
public
SobotCustomHttpUtils
setFileSaveDir
(
String
dir
)
{
mHttpBody
.
setFileSaveDir
(
dir
);
return
this
;
}
/**
* 添加文件---按路径
*
* @param filePath desc
* @return this
*/
public
SobotCustomHttpUtils
addFile
(
String
filePath
)
{
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
())
{
mHttpBody
.
addFile
(
filePath
);
}
else
{
callback
.
onFailed
(
new
FileNotFoundException
(
"NOFile"
));
}
return
this
;
}
/**
* 添加文件---按文件
*
* @param file desc
* @return this
*/
public
SobotCustomHttpUtils
addFile
(
File
file
)
{
if
(
file
.
exists
())
{
mHttpBody
.
addFile
(
file
);
}
else
{
callback
.
onFailed
(
new
FileNotFoundException
(
"NOFile"
));
}
return
this
;
}
/**
* 添加文件---按文件列表
*
* @param fileList desc
* @return this
*/
public
SobotCustomHttpUtils
addFiles
(
List
<
File
>
fileList
)
{
for
(
File
file
:
fileList
)
{
if
(
file
.
exists
())
{
mHttpBody
.
addFile
(
file
);
}
else
{
callback
.
onFailed
(
new
FileNotFoundException
(
"NOFile"
));
}
}
return
this
;
}
/**
* 添加文件---按文件路径列表
*
* @param filePaths desc
* @return this
*/
public
SobotCustomHttpUtils
addFilesByPath
(
List
<
String
>
filePaths
)
{
for
(
String
filePath
:
filePaths
)
{
if
(
new
File
(
filePath
).
exists
())
{
mHttpBody
.
addFile
(
filePath
);
}
else
{
callback
.
onFailed
(
new
FileNotFoundException
(
"NOFile"
));
}
}
return
this
;
}
/**
* 执行Get请求
*
* @param callback desc
* @return this
*/
public
SobotCustomHttpUtils
onExecute
(
CommCallback
callback
)
{
this
.
callback
=
callback
;
ProvideHttpRequester
requester
=
new
ProvideHttpRequester
(
new
GetHttpRequester
(
mHttpBody
,
callback
));
requester
.
startRequest
();
//开始请求
return
this
;
}
/**
* 执行Post请求
*
* @param callback desc
* @return this
*/
public
SobotCustomHttpUtils
onExecuteByPost
(
CommCallback
callback
)
{
this
.
callback
=
callback
;
ProvideHttpRequester
requester
=
new
ProvideHttpRequester
(
new
PostHttpRequester
(
mHttpBody
,
callback
));
requester
.
startRequest
();
//开始请求
return
this
;
}
/**
* 下载文件
*
* @param callback desc
* @return this
*/
public
SobotCustomHttpUtils
onExecuteDwonload
(
CommCallback
callback
)
{
this
.
callback
=
callback
;
ProvideHttpRequester
requester
=
new
ProvideHttpRequester
(
new
DownLoadHttpRequester
(
mHttpBody
,
callback
));
requester
.
startRequest
();
//开始请求
return
this
;
}
/**
* 上传文件
*
* @param callback desc
* @return this
*/
public
SobotCustomHttpUtils
onExecuteUpLoad
(
CommCallback
callback
)
{
this
.
callback
=
callback
;
ProvideHttpRequester
requester
=
new
ProvideHttpRequester
(
new
UpLoadHttpRequester
(
mHttpBody
,
callback
));
requester
.
startRequest
();
//开始请求
return
this
;
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/base/GlobalFied.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
base
;
/**
* 全局字段
*/
public
class
GlobalFied
{
public
static
final
int
WHAT_REQ_SUCCESS
=
1001
;
//请求成功
public
static
final
int
WHAT_REQ_FAILED
=
1002
;
//请求失败
public
static
final
int
WHAT_MALFORMED_URL_EXCEPTION
=
1003
;
//url解析异常
public
static
final
int
WHAT_IO_EXCEPTION
=
1004
;
//io异常
public
static
final
int
WHAT_DOWNLOAD_PROGRESS
=
1005
;
//下载回调
public
static
final
int
WHAT_DOWNLOAD_FINISHED
=
1006
;
//下载完成
public
static
final
int
WHAT_UPLOAD_FINISHED
=
1007
;
//上传完成
public
static
final
int
WHAT_UPLOAD_NOT_FILE
=
1008
;
//没有上传的文件
}
sobot_network/src/main/java/com/sobot/network/customhttp/bean/CommCallback.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
bean
;
/**
* 通用回调
*/
public
abstract
class
CommCallback
<
T
>
extends
ICommCallback
<
T
>
{
}
sobot_network/src/main/java/com/sobot/network/customhttp/bean/DownLoadCallBack.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
bean
;
/**
* 下载的回调对象
*/
public
abstract
class
DownLoadCallBack
extends
CommCallback
<
String
>
{
public
void
onDownLoadFinished
()
{
}
public
void
onDownloading
(
long
total
,
long
current
)
{
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/bean/HttpBody.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
bean
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* Http的基本属性类
*/
public
class
HttpBody
{
private
String
url
;
//请求的url
private
String
uploadUrl
;
//文件上传的url
private
int
readTimeOut
=
30
*
1000
;
//默认30s
private
int
connTimeOut
=
5
*
1000
;
//默认5s
private
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
//请求的参数
private
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
//请求头参数
private
String
fileSaveDir
=
"/sdcard/download"
;
//保存文件的目录
private
List
<
File
>
files
=
new
ArrayList
<>();
//需要上传的文件
private
String
contentType
=
"application/x-www-form-urlencoded"
;
// application/json
public
String
getUploadUrl
()
{
return
uploadUrl
;
}
public
HttpBody
setUploadUrl
(
String
uploadUrl
)
{
this
.
uploadUrl
=
uploadUrl
;
return
this
;
}
public
HttpBody
addFile
(
String
filePath
)
{
files
.
add
(
new
File
(
filePath
));
return
this
;
}
public
HttpBody
addFile
(
File
file
)
{
files
.
add
(
file
);
return
this
;
}
public
HttpBody
addFiles
(
List
<
File
>
fileList
)
{
files
.
addAll
(
fileList
);
return
this
;
}
public
HttpBody
addParam
(
String
key
,
Object
value
)
{
params
.
put
(
key
,
value
);
return
this
;
}
public
List
<
File
>
getFiles
()
{
return
files
;
}
public
HttpBody
setFiles
(
List
<
File
>
files
)
{
this
.
files
=
files
;
return
this
;
}
public
String
getFileSaveDir
()
{
return
fileSaveDir
;
}
public
HttpBody
setFileSaveDir
(
String
fileSaveDir
)
{
this
.
fileSaveDir
=
fileSaveDir
;
return
this
;
}
public
int
getReadTimeOut
()
{
return
readTimeOut
;
}
public
HttpBody
setReadTimeOut
(
int
readTimeOut
)
{
this
.
readTimeOut
=
readTimeOut
;
return
this
;
}
public
int
getConnTimeOut
()
{
return
connTimeOut
;
}
public
HttpBody
setConnTimeOut
(
int
connTimeOut
)
{
this
.
connTimeOut
=
connTimeOut
;
return
this
;
}
public
String
getUrl
()
{
return
url
;
}
public
HttpBody
setUrl
(
String
url
)
{
this
.
url
=
url
;
return
this
;
}
public
String
getContentType
()
{
return
contentType
;
}
public
void
setContentType
(
String
contentType
)
{
this
.
contentType
=
contentType
;
}
public
Map
<
String
,
Object
>
getParams
()
{
return
params
;
}
public
HttpBody
setParams
(
Map
<
String
,
Object
>
params
)
{
this
.
params
=
params
;
return
this
;
}
public
Map
<
String
,
String
>
getHeaders
()
{
return
headers
;
}
public
HttpBody
setHeaders
(
Map
<
String
,
String
>
headers
)
{
this
.
headers
=
headers
;
return
this
;
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/bean/ICommCallback.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
bean
;
/**
* 回调的抽象类
*/
public
abstract
class
ICommCallback
<
T
>
{
public
abstract
void
onSucceed
(
T
t
);
public
abstract
void
onFailed
(
Exception
e
);
public
void
onUploadFinished
(
String
result
)
{
}
public
void
onDownLoadFinished
()
{
}
public
void
onDownloading
(
long
total
,
long
current
)
{
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/bean/StringCallBack.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
bean
;
/**
* json字符串的回调对象
*/
public
abstract
class
StringCallBack
extends
CommCallback
<
String
>
{
}
sobot_network/src/main/java/com/sobot/network/customhttp/bean/UploadCallBack.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
bean
;
/**
* 上传的回调对象
*/
public
abstract
class
UploadCallBack
extends
CommCallback
<
String
>
{
public
void
onUploadFinished
()
{
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/module/DownLoadHttpRequester.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
module
;
import
android.os.Bundle
;
import
android.os.Message
;
import
com.sobot.network.customhttp.base.GlobalFied
;
import
com.sobot.network.customhttp.bean.HttpBody
;
import
com.sobot.network.customhttp.bean.ICommCallback
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.Map
;
import
java.util.Set
;
/**
* 文件下载的网络请求器
*/
public
class
DownLoadHttpRequester
extends
HttpRequester
{
public
DownLoadHttpRequester
(
HttpBody
mHttpBody
,
ICommCallback
callback
)
{
this
.
mHttpBody
=
mHttpBody
;
this
.
callback
=
callback
;
}
@Override
public
void
request
()
{
new
Thread
()
{
@Override
public
void
run
()
{
try
{
URL
url
=
new
URL
(
mHttpBody
.
getUrl
());
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setReadTimeout
(
mHttpBody
.
getReadTimeOut
());
conn
.
setConnectTimeout
(
mHttpBody
.
getConnTimeOut
());
conn
.
setRequestProperty
(
"Accept-Encoding"
,
"identity"
);
if
(
mHttpBody
.
getHeaders
()
!=
null
)
{
Set
<
Map
.
Entry
<
String
,
String
>>
entries
=
mHttpBody
.
getHeaders
().
entrySet
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
entries
)
{
conn
.
setRequestProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
if
(
conn
.
getResponseCode
()
==
200
)
{
InputStream
is
=
conn
.
getInputStream
();
int
len
=
0
;
byte
[]
buf
=
new
byte
[
1024
*
1024
];
File
file
=
new
File
(
mHttpBody
.
getFileSaveDir
());
if
(
file
.
exists
())
{
file
.
delete
();
}
long
contentLength
=
conn
.
getContentLength
();
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
long
curProgress
=
0
;
while
((
len
=
is
.
read
(
buf
))
!=
-
1
)
{
fos
.
write
(
buf
,
0
,
len
);
curProgress
+=
len
;
Message
msg
=
mHandler
.
obtainMessage
();
msg
.
what
=
GlobalFied
.
WHAT_DOWNLOAD_PROGRESS
;
Bundle
bundle
=
new
Bundle
();
bundle
.
putLong
(
"contentLength"
,
contentLength
);
bundle
.
putLong
(
"curProgress"
,
curProgress
);
msg
.
obj
=
bundle
;
mHandler
.
sendMessage
(
msg
);
}
is
.
close
();
fos
.
close
();
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_DOWNLOAD_FINISHED
);
}
else
{
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_REQ_FAILED
);
}
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_MALFORMED_URL_EXCEPTION
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_IO_EXCEPTION
);
}
}
}.
start
();
}
private
String
getFileName
()
{
return
mHttpBody
.
getUrl
().
substring
(
mHttpBody
.
getUrl
().
lastIndexOf
(
"/"
)
+
1
);
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/module/GetHttpRequester.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
module
;
import
android.os.Message
;
import
com.sobot.network.customhttp.base.GlobalFied
;
import
com.sobot.network.customhttp.bean.HttpBody
;
import
com.sobot.network.customhttp.bean.ICommCallback
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.Map
;
import
java.util.Set
;
/**
* get请求器
*/
public
class
GetHttpRequester
extends
HttpRequester
{
private
static
final
String
TAG
=
"GetHttpRequester"
;
public
GetHttpRequester
(
HttpBody
mHttpBody
,
ICommCallback
callback
)
{
this
.
mHttpBody
=
mHttpBody
;
this
.
callback
=
callback
;
}
@Override
public
void
request
()
{
new
Thread
()
{
@Override
public
void
run
()
{
String
urlPath
=
mHttpBody
.
getUrl
();
try
{
if
(
getParams
()
!=
null
)
{
//判断是否有参数
urlPath
+=
"?"
+
getParams
();
}
URL
url
=
new
URL
(
urlPath
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setReadTimeout
(
mHttpBody
.
getReadTimeOut
());
conn
.
setConnectTimeout
(
mHttpBody
.
getConnTimeOut
());
conn
.
setDoInput
(
true
);
conn
.
setUseCaches
(
true
);
conn
.
setRequestProperty
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
if
(
mHttpBody
.
getHeaders
()
!=
null
)
{
Set
<
Map
.
Entry
<
String
,
String
>>
entries
=
mHttpBody
.
getHeaders
().
entrySet
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
entries
)
{
conn
.
setRequestProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
if
(
conn
.
getResponseCode
()
==
200
)
{
InputStream
is
=
conn
.
getInputStream
();
int
len
=
0
;
byte
[]
buf
=
new
byte
[
1024
*
1024
];
StringBuilder
json
=
new
StringBuilder
();
while
((
len
=
is
.
read
(
buf
))
!=
-
1
)
{
json
.
append
(
new
String
(
buf
,
0
,
len
));
}
is
.
close
();
Message
msg
=
mHandler
.
obtainMessage
();
msg
.
what
=
GlobalFied
.
WHAT_REQ_SUCCESS
;
msg
.
obj
=
json
.
toString
();
mHandler
.
sendMessage
(
msg
);
}
else
{
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_REQ_FAILED
);
}
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_MALFORMED_URL_EXCEPTION
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_IO_EXCEPTION
);
}
}
}.
start
();
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/module/HttpRequester.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
module
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Message
;
import
com.sobot.network.customhttp.base.GlobalFied
;
import
com.sobot.network.customhttp.bean.HttpBody
;
import
com.sobot.network.customhttp.bean.ICommCallback
;
import
com.sobot.network.http.log.SobotNetLogUtils
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.MalformedURLException
;
import
java.net.URLEncoder
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Set
;
/**
* 网络请求器
*/
public
abstract
class
HttpRequester
{
HttpBody
mHttpBody
;
ICommCallback
callback
;
Handler
mHandler
=
new
Handler
()
{
@Override
public
void
handleMessage
(
Message
msg
)
{
switch
(
msg
.
what
)
{
case
GlobalFied
.
WHAT_REQ_SUCCESS
:
//请求成功
String
json
=
(
String
)
msg
.
obj
;
// printJson(json);//print json string
callback
.
onSucceed
(
json
);
break
;
case
GlobalFied
.
WHAT_IO_EXCEPTION
:
//网络异常、超时
printErrorMsg
(
"IOException"
);
callback
.
onFailed
(
new
IOException
(
"IOException"
));
break
;
case
GlobalFied
.
WHAT_REQ_FAILED
:
//505等服务器错误
printErrorMsg
(
"ServerException"
);
callback
.
onFailed
(
new
Exception
(
"ServerException"
));
break
;
case
GlobalFied
.
WHAT_MALFORMED_URL_EXCEPTION
:
//url错误异常
printErrorMsg
(
"MalformedURLException"
);
callback
.
onFailed
(
new
MalformedURLException
(
"MalformedURLException"
));
break
;
case
GlobalFied
.
WHAT_DOWNLOAD_PROGRESS
:
//下载进度
Bundle
bundle
=
(
Bundle
)
msg
.
obj
;
long
total
=
bundle
.
getLong
(
"contentLength"
);
long
cur
=
bundle
.
getLong
(
"curProgress"
);
callback
.
onDownloading
(
total
,
cur
);
SobotNetLogUtils
.
i
(
"下载进度"
+
cur
+
"----"
+
total
);
break
;
case
GlobalFied
.
WHAT_DOWNLOAD_FINISHED
:
//下载完成
callback
.
onSucceed
(
"succeed"
);
break
;
case
GlobalFied
.
WHAT_UPLOAD_FINISHED
:
//上传完成
String
response
=
(
String
)
msg
.
obj
;
callback
.
onUploadFinished
(
response
);
break
;
case
GlobalFied
.
WHAT_UPLOAD_NOT_FILE
:
//没有文件
printErrorMsg
(
"NOFile"
);
callback
.
onFailed
(
new
Exception
(
"NOFile"
));
break
;
}
}
};
/**
* 获取请求的参数
*
* @return string
*/
public
String
getParams
()
{
if
(
mHttpBody
.
getParams
()
==
null
||
mHttpBody
.
getParams
().
size
()
==
0
)
{
//判断是否有参数
return
null
;
}
Map
<
String
,
Object
>
params
=
mHttpBody
.
getParams
();
String
data
=
""
;
Set
<
Map
.
Entry
<
String
,
Object
>>
entrySet
=
params
.
entrySet
();
Iterator
<
Map
.
Entry
<
String
,
Object
>>
iterator
=
entrySet
.
iterator
();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
String
,
Object
>
me
=
iterator
.
next
();
String
value
=
""
+
me
.
getValue
();
try
{
value
=
URLEncoder
.
encode
(
value
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
data
+=
me
.
getKey
()
+
"="
+
value
+
"&"
;
}
data
=
data
.
substring
(
0
,
data
.
lastIndexOf
(
"&"
));
//去掉最后一个&
return
data
;
}
private
void
printJson
(
String
json
)
{
SobotNetLogUtils
.
i
(
"|------- The Json start -------|\n\n\t"
+
json
.
toString
()
+
"\n\n|------- The Json end -------|"
);
}
public
void
printErrorMsg
(
String
json
)
{
SobotNetLogUtils
.
e
(
"|———————————— The error msg ————————————|\n\n\t"
+
json
.
toString
()
+
"\n\n|———————————— The error msg ————————————|"
);
}
/**
* 开始请求了
*/
public
abstract
void
request
();
}
sobot_network/src/main/java/com/sobot/network/customhttp/module/PostHttpRequester.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
module
;
import
android.os.Message
;
import
com.sobot.network.customhttp.base.GlobalFied
;
import
com.sobot.network.customhttp.bean.HttpBody
;
import
com.sobot.network.customhttp.bean.ICommCallback
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.Map
;
import
java.util.Set
;
/**
* post请求器
*/
public
class
PostHttpRequester
extends
HttpRequester
{
private
static
final
String
TAG
=
"PostHttpRequester"
;
public
PostHttpRequester
(
HttpBody
mHttpBody
,
ICommCallback
callback
)
{
this
.
mHttpBody
=
mHttpBody
;
this
.
callback
=
callback
;
}
@Override
public
void
request
()
{
new
Thread
()
{
@Override
public
void
run
()
{
String
urlPath
=
mHttpBody
.
getUrl
();
try
{
URL
url
=
new
URL
(
urlPath
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setReadTimeout
(
mHttpBody
.
getReadTimeOut
());
conn
.
setConnectTimeout
(
mHttpBody
.
getConnTimeOut
());
conn
.
setDoInput
(
true
);
conn
.
setUseCaches
(
true
);
conn
.
setRequestProperty
(
"Content-Type"
,
mHttpBody
.
getContentType
());
if
(
mHttpBody
.
getHeaders
()
!=
null
)
{
Set
<
Map
.
Entry
<
String
,
String
>>
entries
=
mHttpBody
.
getHeaders
().
entrySet
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
entries
)
{
conn
.
setRequestProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
conn
.
setRequestMethod
(
"POST"
);
conn
.
setDoOutput
(
true
);
DataOutputStream
out
=
new
DataOutputStream
(
conn
.
getOutputStream
());
out
.
writeBytes
(
getParams
());
out
.
flush
();
out
.
close
();
if
(
conn
.
getResponseCode
()
==
200
)
{
InputStream
is
=
conn
.
getInputStream
();
int
len
=
0
;
byte
[]
buf
=
new
byte
[
1024
*
1024
];
StringBuilder
json
=
new
StringBuilder
();
while
((
len
=
is
.
read
(
buf
))
!=
-
1
)
{
json
.
append
(
new
String
(
buf
,
0
,
len
));
}
is
.
close
();
Message
msg
=
mHandler
.
obtainMessage
();
msg
.
what
=
GlobalFied
.
WHAT_REQ_SUCCESS
;
msg
.
obj
=
json
.
toString
();
mHandler
.
sendMessage
(
msg
);
}
else
{
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_REQ_FAILED
);
}
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_MALFORMED_URL_EXCEPTION
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_IO_EXCEPTION
);
}
}
}.
start
();
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/module/ProvideHttpRequester.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
module
;
/**
* 提供http请求器
*/
public
class
ProvideHttpRequester
{
private
com
.
sobot
.
network
.
customhttp
.
module
.
HttpRequester
mHttpRequester
;
public
ProvideHttpRequester
(
HttpRequester
mHttpRequester
)
{
this
.
mHttpRequester
=
mHttpRequester
;
}
/**
* 开始请求
*/
public
void
startRequest
()
{
mHttpRequester
.
request
();
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/module/UpLoadHttpRequester.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
module
;
import
android.os.Message
;
import
com.sobot.network.customhttp.base.GlobalFied
;
import
com.sobot.network.customhttp.bean.HttpBody
;
import
com.sobot.network.customhttp.bean.ICommCallback
;
import
java.io.DataOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.UUID
;
/**
* 单文件上传
*/
public
class
UpLoadHttpRequester
extends
HttpRequester
{
public
UpLoadHttpRequester
(
HttpBody
mHttpBody
,
ICommCallback
callback
)
{
this
.
mHttpBody
=
mHttpBody
;
this
.
callback
=
callback
;
}
@Override
public
void
request
()
{
new
Thread
()
{
@Override
public
void
run
()
{
String
BOUNDARY
=
UUID
.
randomUUID
().
toString
();
String
PREFIX
=
"--"
,
LINE_END
=
"\r\n"
;
String
CONTENT_TYPE
=
"multipart/form-data"
;
try
{
URL
url
=
new
URL
(
mHttpBody
.
getUploadUrl
());
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setReadTimeout
(
mHttpBody
.
getReadTimeOut
());
conn
.
setConnectTimeout
(
mHttpBody
.
getConnTimeOut
());
conn
.
setDoInput
(
true
);
conn
.
setDoOutput
(
true
);
conn
.
setUseCaches
(
false
);
conn
.
setRequestMethod
(
"POST"
);
conn
.
setRequestProperty
(
"Charset"
,
"utf-8"
);
// 设置编码
conn
.
setRequestProperty
(
"connection"
,
"keep-alive"
);
conn
.
setRequestProperty
(
"Content-Type"
,
CONTENT_TYPE
+
";boundary="
+
BOUNDARY
);
if
(
mHttpBody
.
getHeaders
()
!=
null
)
{
Set
<
Map
.
Entry
<
String
,
String
>>
entries
=
mHttpBody
.
getHeaders
().
entrySet
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
entries
)
{
conn
.
setRequestProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
OutputStream
outputSteam
=
conn
.
getOutputStream
();
DataOutputStream
dos
=
new
DataOutputStream
(
outputSteam
);
if
(
mHttpBody
.
getFiles
()
!=
null
&&
mHttpBody
.
getFiles
().
size
()
>
0
)
{
//有文件才能上传
for
(
File
file
:
mHttpBody
.
getFiles
())
{
StringBuffer
sb
=
new
StringBuffer
();
if
(
mHttpBody
.
getParams
()
!=
null
||
mHttpBody
.
getParams
().
size
()
>
0
)
{
//根据格式,开始拼接文本参数
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
mHttpBody
.
getParams
().
entrySet
())
{
sb
.
append
(
PREFIX
).
append
(
BOUNDARY
).
append
(
LINE_END
);
//分界符
sb
.
append
(
"Content-Disposition: form-data; name=\""
+
entry
.
getKey
()
+
"\""
+
LINE_END
);
sb
.
append
(
"Content-Type: text/plain; charset=utf-8"
+
LINE_END
);
sb
.
append
(
"Content-Transfer-Encoding: 8bit"
+
LINE_END
);
sb
.
append
(
LINE_END
);
sb
.
append
(
entry
.
getValue
());
sb
.
append
(
LINE_END
);
//换行!
}
}
sb
.
append
(
PREFIX
);
sb
.
append
(
BOUNDARY
);
sb
.
append
(
LINE_END
);
sb
.
append
(
"Content-Disposition: form-data; name=\"file\"; filename=\""
+
file
.
getName
()
+
"\""
+
LINE_END
);
sb
.
append
(
"Content-Type: application/octet-stream; charset=utf-8"
+
LINE_END
);
sb
.
append
(
LINE_END
);
dos
.
write
(
sb
.
toString
().
getBytes
());
FileInputStream
fis
=
new
FileInputStream
(
file
);
byte
[]
bytes
=
new
byte
[
1024
*
1024
];
int
len
=
0
;
while
((
len
=
fis
.
read
(
bytes
))
!=
-
1
)
{
dos
.
write
(
bytes
,
0
,
len
);
}
fis
.
close
();
dos
.
write
(
LINE_END
.
getBytes
());
}
byte
[]
end_data
=
(
PREFIX
+
BOUNDARY
+
PREFIX
+
LINE_END
)
.
getBytes
();
dos
.
write
(
end_data
);
dos
.
flush
();
dos
.
close
();
StringBuilder
json
=
new
StringBuilder
();
if
(
conn
.
getResponseCode
()
==
200
)
{
int
length
=
0
;
byte
buf
[]
=
new
byte
[
1024
*
1024
];
InputStream
cis
=
conn
.
getInputStream
();
while
((
length
=
cis
.
read
(
buf
))
!=
-
1
)
{
json
.
append
(
new
String
(
buf
,
0
,
length
));
}
cis
.
close
();
Message
msg
=
mHandler
.
obtainMessage
();
msg
.
what
=
GlobalFied
.
WHAT_UPLOAD_FINISHED
;
msg
.
obj
=
json
.
toString
();
mHandler
.
sendMessage
(
msg
);
}
else
{
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_REQ_FAILED
);
}
}
else
{
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_UPLOAD_NOT_FILE
);
}
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_MALFORMED_URL_EXCEPTION
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
mHandler
.
sendEmptyMessage
(
GlobalFied
.
WHAT_IO_EXCEPTION
);
}
}
}.
start
();
}
}
sobot_network/src/main/java/com/sobot/network/customhttp/utils/FailedMsgUtils.java
0 → 100644
View file @
3a45670f
package
com
.
sobot
.
network
.
customhttp
.
utils
;
import
android.text.TextUtils
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 异常信息工具类
*/
public
class
FailedMsgUtils
{
private
static
Map
<
String
,
Object
>
errList
=
new
HashMap
<>();
//错误信息对照表
static
{
errList
.
put
(
"IOException"
,
"网络连接异常"
);
errList
.
put
(
"ServerException"
,
"服务器维护中"
);
errList
.
put
(
"MalformedURLException"
,
"找不到服务器"
);
errList
.
put
(
"NOFile"
,
"找不到文件"
);
}
/**
* 获取错误信息对应的字符串
*@param errMsg desc
* @return msgStr
*/
public
static
String
getErrMsgStr
(
String
errMsg
)
{
String
msgStr
=
(
String
)
errList
.
get
(
errMsg
);
if
(
TextUtils
.
isEmpty
(
msgStr
))
{
msgStr
=
"未知错误"
;
}
return
msgStr
;
}
/**
* 获取错误信息对应的字符串
*@param throwable desc
* @return msgStr
*/
public
static
String
getErrMsgStr
(
Throwable
throwable
)
{
return
getErrMsgStr
(
throwable
.
getMessage
());
}
}
sobot_network/src/main/java/com/sobot/network/http/HttpBaseUtils.java
View file @
3a45670f
This diff is collapsed.
Click to expand it.
sobot_network/src/main/java/com/sobot/network/http/builder/GetBuilder.java
View file @
3a45670f
...
...
@@ -19,7 +19,7 @@ public class GetBuilder extends OkHttpRequestBuilder implements HasParamsable
return
new
GetRequest
(
url
,
tag
,
params
,
headers
).
build
();
}
protected
String
appendParams
(
String
url
,
Map
<
String
,
String
>
params
)
protected
String
appendParams
(
String
url
,
Map
<
String
,
Object
>
params
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
url
+
"?"
);
...
...
@@ -50,7 +50,7 @@ public class GetBuilder extends OkHttpRequestBuilder implements HasParamsable
}
@Override
public
GetBuilder
params
(
Map
<
String
,
String
>
params
)
public
GetBuilder
params
(
Map
<
String
,
Object
>
params
)
{
this
.
params
=
params
;
return
this
;
...
...
@@ -61,7 +61,7 @@ public class GetBuilder extends OkHttpRequestBuilder implements HasParamsable
{
if
(
this
.
params
==
null
)
{
params
=
new
LinkedHashMap
<
String
,
String
>();
params
=
new
LinkedHashMap
<
String
,
Object
>();
}
params
.
put
(
key
,
val
);
return
this
;
...
...
sobot_network/src/main/java/com/sobot/network/http/builder/HasParamsable.java
View file @
3a45670f
...
...
@@ -4,7 +4,7 @@ import java.util.Map;
public
interface
HasParamsable
{
public
abstract
OkHttpRequestBuilder
params
(
Map
<
String
,
String
>
params
);
public
abstract
OkHttpRequestBuilder
params
(
Map
<
String
,
Object
>
params
);
public
abstract
OkHttpRequestBuilder
addParams
(
String
key
,
String
val
);
...
...
sobot_network/src/main/java/com/sobot/network/http/builder/OkHttpRequestBuilder.java
View file @
3a45670f
...
...
@@ -9,7 +9,7 @@ public abstract class OkHttpRequestBuilder
protected
String
url
;
protected
Object
tag
;
protected
Map
<
String
,
String
>
headers
;
protected
Map
<
String
,
String
>
params
;
protected
Map
<
String
,
Object
>
params
;
public
abstract
OkHttpRequestBuilder
url
(
String
url
);
...
...
sobot_network/src/main/java/com/sobot/network/http/builder/PostFormBuilder.java
View file @
3a45670f
...
...
@@ -68,7 +68,7 @@ public class PostFormBuilder extends OkHttpRequestBuilder implements HasParamsab
}
@Override
public
PostFormBuilder
params
(
Map
<
String
,
String
>
params
)
public
PostFormBuilder
params
(
Map
<
String
,
Object
>
params
)
{
this
.
params
=
params
;
return
this
;
...
...
@@ -79,7 +79,7 @@ public class PostFormBuilder extends OkHttpRequestBuilder implements HasParamsab
{
if
(
this
.
params
==
null
)
{
params
=
new
LinkedHashMap
<
String
,
String
>();
params
=
new
LinkedHashMap
<
String
,
Object
>();
}
params
.
put
(
key
,
val
);
return
this
;
...
...
sobot_network/src/main/java/com/sobot/network/http/builder/PostMultipartFormBuilder.java
View file @
3a45670f
...
...
@@ -68,7 +68,7 @@ public class PostMultipartFormBuilder extends OkHttpRequestBuilder implements Ha
}
@Override
public
PostMultipartFormBuilder
params
(
Map
<
String
,
String
>
params
)
public
PostMultipartFormBuilder
params
(
Map
<
String
,
Object
>
params
)
{
this
.
params
=
params
;
return
this
;
...
...
@@ -79,7 +79,7 @@ public class PostMultipartFormBuilder extends OkHttpRequestBuilder implements Ha
{
if
(
this
.
params
==
null
)
{
params
=
new
LinkedHashMap
<
String
,
String
>();
params
=
new
LinkedHashMap
<
String
,
Object
>();
}
params
.
put
(
key
,
val
);
return
this
;
...
...
sobot_network/src/main/java/com/sobot/network/http/request/GetRequest.java
View file @
3a45670f
...
...
@@ -7,7 +7,7 @@ import okhttp3.RequestBody;
public
class
GetRequest
extends
OkHttpRequest
{
public
GetRequest
(
String
url
,
Object
tag
,
Map
<
String
,
String
>
params
,
Map
<
String
,
String
>
headers
)
public
GetRequest
(
String
url
,
Object
tag
,
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
)
{
super
(
url
,
tag
,
params
,
headers
);
}
...
...
sobot_network/src/main/java/com/sobot/network/http/request/OkHttpRequest.java
View file @
3a45670f
...
...
@@ -14,7 +14,7 @@ public abstract class OkHttpRequest
{
protected
String
url
;
protected
Object
tag
;
protected
Map
<
String
,
String
>
params
;
protected
Map
<
String
,
Object
>
params
;
protected
Map
<
String
,
String
>
headers
;
protected
Request
.
Builder
builder
=
new
Request
.
Builder
();
...
...
@@ -22,7 +22,7 @@ public abstract class OkHttpRequest
protected
transient
ProgressRequestBody
.
UploadInterceptor
uploadInterceptor
;
protected
OkHttpRequest
(
String
url
,
Object
tag
,
Map
<
String
,
String
>
params
,
Map
<
String
,
String
>
headers
)
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
)
{
this
.
url
=
url
;
this
.
tag
=
tag
;
...
...
sobot_network/src/main/java/com/sobot/network/http/request/OtherRequest.java
View file @
3a45670f
...
...
@@ -20,7 +20,7 @@ public class OtherRequest extends OkHttpRequest
private
String
method
;
private
String
content
;
public
OtherRequest
(
RequestBody
requestBody
,
String
content
,
String
method
,
String
url
,
Object
tag
,
Map
<
String
,
String
>
params
,
Map
<
String
,
String
>
headers
)
public
OtherRequest
(
RequestBody
requestBody
,
String
content
,
String
method
,
String
url
,
Object
tag
,
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
)
{
super
(
url
,
tag
,
params
,
headers
);
this
.
requestBody
=
requestBody
;
...
...
sobot_network/src/main/java/com/sobot/network/http/request/PostFileRequest.java
View file @
3a45670f
...
...
@@ -16,7 +16,7 @@ public class PostFileRequest extends OkHttpRequest
private
File
file
;
private
MediaType
mediaType
;
public
PostFileRequest
(
String
url
,
Object
tag
,
Map
<
String
,
String
>
params
,
Map
<
String
,
String
>
headers
,
File
file
,
MediaType
mediaType
)
public
PostFileRequest
(
String
url
,
Object
tag
,
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
,
File
file
,
MediaType
mediaType
)
{
super
(
url
,
tag
,
params
,
headers
);
this
.
file
=
file
;
...
...
sobot_network/src/main/java/com/sobot/network/http/request/PostFormRequest.java
View file @
3a45670f
...
...
@@ -20,7 +20,7 @@ import okhttp3.RequestBody;
public
class
PostFormRequest
extends
OkHttpRequest
{
private
List
<
PostFormBuilder
.
FileInput
>
files
;
public
PostFormRequest
(
String
url
,
Object
tag
,
Map
<
String
,
String
>
params
,
public
PostFormRequest
(
String
url
,
Object
tag
,
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
,
List
<
PostFormBuilder
.
FileInput
>
files
)
{
super
(
url
,
tag
,
params
,
headers
);
this
.
files
=
files
;
...
...
@@ -83,7 +83,7 @@ public class PostFormRequest extends OkHttpRequest {
builder
.
addPart
(
Headers
.
of
(
"Content-Disposition"
,
"form-data; name=\""
+
key
+
"\""
),
RequestBody
.
create
(
null
,
params
.
get
(
key
)));
RequestBody
.
create
(
null
,
params
.
get
(
key
)
.
toString
()
));
}
}
}
...
...
@@ -92,7 +92,7 @@ public class PostFormRequest extends OkHttpRequest {
if
(
params
!=
null
)
{
for
(
String
key
:
params
.
keySet
())
{
if
(
params
.
get
(
key
)
!=
null
)
{
builder
.
add
(
key
,
params
.
get
(
key
));
builder
.
add
(
key
,
params
.
get
(
key
)
.
toString
()
);
}
}
}
...
...
sobot_network/src/main/java/com/sobot/network/http/request/PostMultipartFormRequest.java
View file @
3a45670f
...
...
@@ -20,7 +20,7 @@ import okhttp3.RequestBody;
public
class
PostMultipartFormRequest
extends
OkHttpRequest
{
private
List
<
PostMultipartFormBuilder
.
FileInput
>
files
;
public
PostMultipartFormRequest
(
String
url
,
Object
tag
,
Map
<
String
,
String
>
params
,
public
PostMultipartFormRequest
(
String
url
,
Object
tag
,
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
,
List
<
PostMultipartFormBuilder
.
FileInput
>
files
)
{
super
(
url
,
tag
,
params
,
headers
);
this
.
files
=
files
;
...
...
@@ -77,7 +77,7 @@ public class PostMultipartFormRequest extends OkHttpRequest {
builder
.
addPart
(
Headers
.
of
(
"Content-Disposition"
,
"form-data; name=\""
+
key
+
"\""
),
RequestBody
.
create
(
null
,
params
.
get
(
key
)));
RequestBody
.
create
(
null
,
params
.
get
(
key
)
.
toString
()
));
}
}
}
...
...
@@ -86,7 +86,7 @@ public class PostMultipartFormRequest extends OkHttpRequest {
if
(
params
!=
null
)
{
for
(
String
key
:
params
.
keySet
())
{
if
(
params
.
get
(
key
)
!=
null
)
{
builder
.
add
(
key
,
params
.
get
(
key
));
builder
.
add
(
key
,
params
.
get
(
key
)
.
toString
()
);
}
}
}
...
...
sobot_network/src/main/java/com/sobot/network/http/request/PostStringRequest.java
View file @
3a45670f
...
...
@@ -16,7 +16,7 @@ public class PostStringRequest extends OkHttpRequest
private
MediaType
mediaType
;
public
PostStringRequest
(
String
url
,
Object
tag
,
Map
<
String
,
String
>
params
,
Map
<
String
,
String
>
headers
,
String
content
,
MediaType
mediaType
)
public
PostStringRequest
(
String
url
,
Object
tag
,
Map
<
String
,
Object
>
params
,
Map
<
String
,
String
>
headers
,
String
content
,
MediaType
mediaType
)
{
super
(
url
,
tag
,
params
,
headers
);
this
.
content
=
content
;
...
...
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