增加网络请求日志

This commit is contained in:
老皮 2024-11-01 17:11:32 +08:00
parent 1348d2899c
commit de35a605a7

View File

@ -107,6 +107,9 @@ public class HttpLoggingInterceptor implements Interceptor {
String name = headers.name(i); String name = headers.name(i);
// Skip headers from the request body as they are explicitly logged above. // Skip headers from the request body as they are explicitly logged above.
if (!"Content-Type".equalsIgnoreCase(name) && !"Content-Length".equalsIgnoreCase(name)) { if (!"Content-Type".equalsIgnoreCase(name) && !"Content-Length".equalsIgnoreCase(name)) {
if (i == 0){
log("请求头:");
}
log("\t" + name + ": " + headers.value(i)); log("\t" + name + ": " + headers.value(i));
} }
} }
@ -114,6 +117,7 @@ public class HttpLoggingInterceptor implements Interceptor {
log(" "); log(" ");
if (logBody && hasRequestBody) { if (logBody && hasRequestBody) {
if (isPlaintext(requestBody.contentType())) { if (isPlaintext(requestBody.contentType())) {
log("request Body ");
bodyToString(request); bodyToString(request);
} else { } else {
log("\tbody: maybe [binary body], omitted!"); log("\tbody: maybe [binary body], omitted!");