diff --git a/app/build.gradle b/app/build.gradle index c2f4ce1..24672dc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,7 +76,7 @@ dependencies { implementation 'com.github.getActivity:Toaster:12.6' // 权限请求框架:https://github.com/getActivity/XXPermissions - implementation 'com.github.getActivity:XXPermissions:18.5' + implementation 'com.github.getActivity:XXPermissions:18.6' // 标题栏框架:https://github.com/getActivity/TitleBar implementation 'com.github.getActivity:TitleBar:10.5' diff --git a/app/src/main/java/com/hjq/easy/demo/http/api/SearchBlogsApi.java b/app/src/main/java/com/hjq/easy/demo/http/api/SearchBlogsApi.java index cf19c3c..c496cc4 100644 --- a/app/src/main/java/com/hjq/easy/demo/http/api/SearchBlogsApi.java +++ b/app/src/main/java/com/hjq/easy/demo/http/api/SearchBlogsApi.java @@ -1,10 +1,8 @@ package com.hjq.easy.demo.http.api; import androidx.annotation.NonNull; - import com.hjq.http.annotation.HttpRename; import com.hjq.http.config.IRequestApi; - import java.util.List; /** @@ -30,7 +28,7 @@ public SearchBlogsApi setKeyword(String keyword) { return this; } - public final static class Bean { + public static final class Bean { private int curPage; private int offset; diff --git a/app/src/main/java/com/hjq/easy/demo/http/model/HttpData.java b/app/src/main/java/com/hjq/easy/demo/http/model/HttpData.java index f5ee9c6..70ffd8c 100644 --- a/app/src/main/java/com/hjq/easy/demo/http/model/HttpData.java +++ b/app/src/main/java/com/hjq/easy/demo/http/model/HttpData.java @@ -1,8 +1,7 @@ package com.hjq.easy.demo.http.model; import androidx.annotation.Nullable; - -import okhttp3.Headers; +import java.util.Map; /** * author : Android 轮子哥 @@ -14,7 +13,7 @@ public class HttpData { /** 响应头 */ @Nullable - private Headers responseHeaders; + private Map responseHeaders; /** 返回码 */ private int errorCode; @@ -24,12 +23,12 @@ public class HttpData { @Nullable private T data; - public void setResponseHeaders(@Nullable Headers responseHeaders) { + public void setResponseHeaders(@Nullable Map responseHeaders) { this.responseHeaders = responseHeaders; } @Nullable - public Headers getResponseHeaders() { + public Map getResponseHeaders() { return responseHeaders; } diff --git a/app/src/main/java/com/hjq/easy/demo/http/model/RequestHandler.java b/app/src/main/java/com/hjq/easy/demo/http/model/RequestHandler.java index 2d6f306..a058086 100644 --- a/app/src/main/java/com/hjq/easy/demo/http/model/RequestHandler.java +++ b/app/src/main/java/com/hjq/easy/demo/http/model/RequestHandler.java @@ -31,6 +31,8 @@ import java.lang.reflect.Type; import java.net.SocketTimeoutException; import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; import okhttp3.Headers; import okhttp3.Response; import okhttp3.ResponseBody; @@ -116,7 +118,14 @@ public Object requestSuccess(@NonNull HttpRequest httpRequest, @NonNull Respo if (result instanceof HttpData) { HttpData model = (HttpData) result; - model.setResponseHeaders(response.headers()); + Headers headers = response.headers(); + int headersSize = headers.size(); + Map headersMap = new HashMap<>(headersSize); + for (int i = 0; i < headersSize; i++) { + headersMap.put(headers.name(i), headers.value(i)); + } + // Github issue 地址:https://github.com/getActivity/EasyHttp/issues/233 + model.setResponseHeaders(headersMap); if (model.isRequestSuccess()) { // 代表执行成功