提交 8e73a322 编写于 作者: J jessyan

improve RequestIntercept

上级 205a8017
......@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -112,21 +112,18 @@ public class WEApplication extends BaseApplication {
}
//这里如果发现token过期,可以先请求最新的token,然后在拿新的token去重新请求之前的http请求
//这里如果发现token过期,可以先请求最新的token,然后在拿新的token放入request里去重新请求
//注意在这个回调之前已经调用过proceed,所以这里必须自己去建立网络请求,如使用okhttp使用新的request去请求
// create a new request and modify it accordingly using the new token
// Request newRequest = chain.request().newBuilder().header("token", newToken)
// .build();
//
// // retry the request
//
// response.body().close();
// try {
// return chain.proceed(newRequest);
// } catch (IOException e) {
// e.printStackTrace();
// }
//如果使用okhttp将新的请求,请求成功后,将返回的response return出去即可
//如果需要返回新的结果,则直接把response参数返回出去
//如果需要返回新的结果,则直接把response参数返回出去
return response;
}
......
......@@ -4,7 +4,6 @@ import android.support.annotation.NonNull;
import com.jess.arms.utils.ZipHelper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
......@@ -78,17 +77,9 @@ public class RequestIntercept implements Interceptor {
//解析response content
if (encoding != null && encoding.equalsIgnoreCase("gzip")) {//content使用gzip压缩
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
clone.writeTo(outputStream);
byte[] bytes = outputStream.toByteArray();
bodyString = ZipHelper.decompressForGzip(bytes);//解压
outputStream.close();
bodyString = ZipHelper.decompressForGzip(clone.readByteArray());//解压
} else if (encoding != null && encoding.equalsIgnoreCase("zlib")) {//content使用zlib压缩
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
clone.writeTo(outputStream);
byte[] bytes = outputStream.toByteArray();
bodyString = ZipHelper.decompressToStringForZlib(bytes);//解压
outputStream.close();
bodyString = ZipHelper.decompressToStringForZlib(clone.readByteArray());//解压
} else {//content没有被压缩
Charset charset = Charset.forName("UTF-8");
MediaType contentType = responseBody.contentType();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册