【发布时间】:2022-07-05 17:53:54
【问题描述】:
请求代码
var myClient: HttpClient = HttpClient(Android) {
// Logging
install(Logging) {
logger = Logger.ANDROID
level = LogLevel.BODY
}
}
尝试请求 URL 时
myClient.get(\"https://www.sample.com/state\")
尝试运行请求并得到以下请求日志
2022-07-05 11:20:58.667 977-1021/? W/System.err: [DefaultDispatcher-worker-1] INFO io.ktor.client.HttpClient - REQUEST: https://www.sample.com/state
2022-07-05 11:20:58.667 977-1021/? W/System.err: METHOD: HttpMethod(value=GET)
2022-07-05 11:20:58.667 977-1021/? W/System.err: BODY Content-Type: null
2022-07-05 11:20:58.667 977-1021/? W/System.err: BODY START
2022-07-05 11:20:58.667 977-1021/? W/System.err:
2022-07-05 11:20:58.667 977-1021/? W/System.err: BODY END
响应日志
2022-07-05 11:20:58.924 977-2181/? W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - RESPONSE: 200 OK
2022-07-05 11:20:58.924 977-2181/? W/System.err: METHOD: HttpMethod(value=GET)
2022-07-05 11:20:58.924 977-2181/? W/System.err: FROM: https://www.sample.com/state
2022-07-05 11:20:58.924 977-2181/? W/System.err: BODY Content-Type: application/json; charset=utf-8
2022-07-05 11:20:58.924 977-2181/? W/System.err: BODY START
2022-07-05 11:20:58.924 977-2181/? W/System.err: \"idle\"
2022-07-05 11:20:58.924 977-2181/? W/System.err: BODY END
在日志中,显示请求 URL https://www.sample.com/state 两次。
出于安全原因,我们不想在日志中显示此 URL。
如何设置或操作不显示此网址?
kotlin 版本和 ktor 版本
def kotlin_version = \'1.6.21\'
implementation \"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version\"
def kotlinx_coroutines_version = \'1.6.1\'
implementation \"org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_coroutines_version\"
implementation \"org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinx_coroutines_version\"
def ktor_version = \'2.0.2\'
implementation \"io.ktor:ktor-client-core:$ktor_version\"
// HTTP engine: The HTTP client used to perform network requests.
implementation \"io.ktor:ktor-client-android:$ktor_version\"
// Logging
implementation \"io.ktor:ktor-client-logging:$ktor_version\"
-
删除 LogLevel.BODY。通过删除它,您的请求将不会显示在日志中。
-
但除了 URL,所有内容都是必需的 @pratik vekariya
-
我的意思是你不需要添加级别。我用java做过,如果你想看我可以给你看。
-
尝试删除
LogLevel.BODY,日志级别更改为默认(ALL),日志内容一切。 -
i.stack.imgur.com/zZWxY.png 检查此屏幕截图,在此我仅添加了 networkConnectionInterceptor。而且它没有在日志中显示请求
标签: android kotlin ktor ktor-client