본문 바로가기
Android

Android Https body 통신 로그 보기

by kkong93 2022. 10. 27.
반응형
object RetrofitService {
    val baseUrl = "주소"
    var retrofitService: RetrofitService? = null
    val interceptor = HttpLoggingInterceptor()

    fun get(): Retrofit {
        if (GlobalApplication.DEBUG) {
            interceptor.level = HttpLoggingInterceptor.Level.BODY
        } else {
            interceptor.level = HttpLoggingInterceptor.Level.NONE
        }
        val client = OkHttpClient.Builder().addInterceptor(interceptor).connectTimeout(100, TimeUnit.SECONDS).build()
        return Retrofit.Builder().baseUrl(baseUrl).client(client)
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }
}

 

if (GlobalApplication.DEBUG) {
            interceptor.level = HttpLoggingInterceptor.Level.BODY
        } else {
            interceptor.level = HttpLoggingInterceptor.Level.NONE
        }

 

 

디버그 모드일때 http 통신 로그 볼 수 있음

 

 

 


build.gradle (:app)

    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.squareup.okhttp3:okhttp:3.4.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
반응형

댓글