Comments (3)
小伙子,后台返回的数据流不能读两次,你可以将之前的 ResponseBody 的数据全部解析出来,然后进行解密,最后重新封装到一个新的 ResponseBody 对象中。
from easyhttp.
我这边这边处理了一下,目前请求正常,有时间的话麻烦大佬看看有没有什么问题
override fun interceptResponse(httpRequest: HttpRequest<*>, response: Response): Response {
val api = httpRequest.requestApi
if (ApiManager.encryptionWhiteListApi.contains(api::class).not()) {
EasyLog.printLog(httpRequest, "不在白名单接口,做加解密操作")
if (response.code() == 200) {
val bytes = response.body()?.bytes()
if (bytes != null) {
val oldResponseBodyStr = String(bytes)
if (oldResponseBodyStr.isNotEmpty()) {
val oldJsonObject = JSONObject(oldResponseBodyStr)
val data = oldJsonObject.optString("data")
if (response.isSuccessful && data.isNullOrEmpty().not()) {
//使用AES解密
val encryptData =
AESUtils.decrypt(
data,
EncryptionAndDecryptionUtils.aesKey
)
if (encryptData.isNotEmpty()) {
if (encryptData.substring(0, 1) == "[") {
//数组
val jsonArray = JSONArray(encryptData)
oldJsonObject.put("data", jsonArray)
} else if (encryptData.substring(0, 1) == "{") {
//对象
val newJsonObject = JSONObject(encryptData)
oldJsonObject.put("data", newJsonObject)
} else {
//具体的数据
oldJsonObject.put("data", encryptData)
}
val resultJson = oldJsonObject.toString()
val newResponseBody =
ResponseBody.create(response.body()?.contentType(), resultJson)
return response.newBuilder().body(newResponseBody).build()
}else{
val newResponseBody =
ResponseBody.create(response.body()?.contentType(), oldResponseBodyStr)
return response.newBuilder().body(newResponseBody).build()
}
}else{
val newResponseBody =
ResponseBody.create(response.body()?.contentType(), oldResponseBodyStr)
return response.newBuilder().body(newResponseBody).build()
}
}else{
val newResponseBody =
ResponseBody.create(response.body()?.contentType(), oldResponseBodyStr)
return response.newBuilder().body(newResponseBody).build()
}
}
}
} else {
EasyLog.printLog(httpRequest, "白名单接口,不做加解密操作")
}
return response
}
from easyhttp.
@clbDream 小伙子,这样写有没有问题这种事情只能靠自己多测试了。
from easyhttp.
Related Issues (20)
- [疑惑]:安全扫描提示HTTPS未校验服务器证书、主机名漏洞 HOT 4
- [Bug]:文件下载超时,文件大小7M,浏览器可以下载,但是使用 EasyHttp 下载超时 HOT 4
- [疑惑]:IRequestCache的缓存配置里getCacheTime是怎么用的 HOT 5
- [疑惑]:You haven't initialized the configuration yet HOT 1
- [建议]:建议可以每个请求单独设置header HOT 2
- [Bug]:USE_CACHE_FIRST模式下,无法更新缓存
- [疑惑]:如何获取当前请求的接口地址 HOT 6
- [建议]:框架可以支持到 protobuf 吗 HOT 3
- [疑惑]: HOT 1
- [Bug]:java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType HOT 9
- [Bug]:网络请求时出现时间解析错误 HOT 3
- [Bug]:java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.gj.aos.chat.mode.HttpData HOT 1
- [疑惑]:可以优先使用IPV4来访问后台服务器吗 HOT 4
- [Bug]:无网络下请求程序闪退 HOT 9
- [Bug]:
- [疑惑]:下载文件配合EasyWindow使用,下载完关闭浮窗报错 HOT 1
- [疑惑]:轮子哥,post接口,body里放数组对象,但是对象没有key 该怎么放啊,着急,在线等 HOT 2
- [疑惑]:下载请求怎么设置超时时间 HOT 5
- [疑惑]:如何添加单个网络请求的header或者cookies HOT 6
- [疑惑]:如何基于此网络框架,封装一个中间层 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from easyhttp.