I have a problem using the Ktor HttpClient library because I can't see all the body content that is being truncated, but I can see them in OkHttp client library through HttpLoggingInterceptor. I am making a simple get request to this URL: /$param/repos (param must be GitHub user name. burakggs)
Solution: I found a answer in MariusVolkhart's answer from How to log requests in ktor http client?. I changed my configuration and replaced engine to OkHttp. But I think if I decided to use different engines for KMM I would run into same truncated json response body problem.
@Provides
@Singleton
fun provideHttpClient(): HttpClient {
return HttpClient(OkHttp) {
engine {
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
addInterceptor(loggingInterceptor)
config {
}
}
}
}
I have a problem using the Ktor HttpClient library because I can't see all the body content that is being truncated, but I can see them in OkHttp client library through HttpLoggingInterceptor. I am making a simple get request to this URL: https://api.github/users/$param/repos (param must be GitHub user name. burakggs)
Solution: I found a answer in MariusVolkhart's answer from How to log requests in ktor http client?. I changed my configuration and replaced engine to OkHttp. But I think if I decided to use different engines for KMM I would run into same truncated json response body problem.
@Provides
@Singleton
fun provideHttpClient(): HttpClient {
return HttpClient(OkHttp) {
engine {
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
addInterceptor(loggingInterceptor)
config {
}
}
}
}
Share
Improve this question
edited Mar 11 at 7:29
brkggs
asked Mar 10 at 13:05
brkggsbrkggs
11 bronze badge
1 Answer
Reset to default 1This is a bug in the default implementation of the Logging
plugin. As a workaround, you can use the OkHttp
logging format:
install(Logging) {
format = LoggingFormat.OkHttp
logger = AndroidLogger("ktor-logger")
level = LogLevel.BODY
}
UPD: The problem with truncation is caused by the Logcat itself which has a limit for a message size for both binary and non-binary logs of ~4076 bytes. See this answer for more information.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744845503a4596810.html
评论列表(0条)