From 2270c82c340e89b40291efa144dd5dd73710ff51 Mon Sep 17 00:00:00 2001 From: nilupeng <qingingrunt2010@qq.com> Date: Wed, 10 Aug 2022 11:53:27 +0000 Subject: [PATCH] 登录信息,头像上传 --- app/src/main/java/com/runt/open/mvvm/retrofit/Interceptor/HttpLoggingInterceptor.java | 34 +++++++++++++++++++--------------- 1 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/runt/open/mvvm/retrofit/Interceptor/HttpLoggingInterceptor.java b/app/src/main/java/com/runt/open/mvvm/retrofit/Interceptor/HttpLoggingInterceptor.java index b0d62f4..59cb698 100644 --- a/app/src/main/java/com/runt/open/mvvm/retrofit/Interceptor/HttpLoggingInterceptor.java +++ b/app/src/main/java/com/runt/open/mvvm/retrofit/Interceptor/HttpLoggingInterceptor.java @@ -1,13 +1,18 @@ package com.runt.open.mvvm.retrofit.Interceptor; import android.util.Log; - +import com.google.gson.Gson; import com.runt.open.mvvm.MyApplication; +import com.runt.open.mvvm.data.PhoneDevice; import com.runt.open.mvvm.retrofit.net.NetWorkCost; import com.runt.open.mvvm.retrofit.net.NetWorkListenear; import com.runt.open.mvvm.retrofit.utils.HttpPrintUtils; +import com.runt.open.mvvm.ui.login.UserBean; import com.runt.open.mvvm.util.DeviceUtil; - +import okhttp3.*; +import okhttp3.internal.http.HttpHeaders; +import okio.Buffer; +import okio.BufferedSource; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -19,18 +24,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; - -import okhttp3.FormBody; -import okhttp3.Headers; -import okhttp3.MediaType; -import okhttp3.MultipartBody; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import okhttp3.ResponseBody; -import okhttp3.internal.http.HttpHeaders; -import okio.Buffer; -import okio.BufferedSource; /** * My father is Object, ites purpose of log打印 @@ -60,8 +53,12 @@ Log.d(TAG, "hashcode:" + hashCode); } Request.Builder requestBuild = requestTemp.newBuilder() + .addHeader("device", new Gson().toJson(PhoneDevice.getDevice())) .addHeader("appVersion", DeviceUtil.getAppVersionName(MyApplication.getApplication())) .addHeader("os", DeviceUtil.isHarmonyOS()? "harmony" : "android"); + if(UserBean.getUser() != null){ + requestBuild.addHeader("token",UserBean.getUser().getToken()); + } Request request = requestBuild.build().newBuilder().build(); ArrayList<String> logArrays = new ArrayList<>(); Response response = null; @@ -205,7 +202,14 @@ if (isPlaintext(buffer)) { logArrays.add("---------->RESPONSE BODY<----------"); if (contentLength != 0) { - logArrays.add(new JSONObject(buffer.clone().readString((charset))).toString(4)); + String str = buffer.clone().readString(charset); + if(str.trim().indexOf("{") == 0) { + logArrays.add(new JSONObject(str).toString(4)); + }else if(str.trim().indexOf("[") == 0) { + logArrays.add(new JSONArray(str).toString(4)); + }else{ + logArrays.add(str); + } } logArrays.add("<-- END HTTP (" + buffer.size() + "-byte body)"); -- Gitblit v1.9.1