Reputation: 96
I'm using Retrofit with OkHttp and Moshi. I have to add the "Accept-Encoding":"gzip, deflate, br"
header myself. But OkHttp adds its own "Accept-Encoding"
header.
Due to this situation, the following error occurs:
com.squareup.moshi.JsonDataException: Expected BEGIN_OBJECT but was STRING at path $
If I remove the "Accept-Encoding":"gzip, deflate, br"
header from the interceptor, it works fine. But I shouldn't remove it.
Here is my code:
class CustomInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response = chain.run {
proceed(
request()
.newBuilder()
.addHeader("Accept-Encoding", "gzip, deflate, br")
.build()
)
}
}
OkHttpClient.Builder()
.addInterceptor(CustomInterceptor())
.build()
Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()
Retrofit.Builder()
.baseUrl("myurl")
.addConverterFactory(MoshiConverterFactory.create(moshi).asLenient())
.client(okHttpClient)
.build()
How can I solve this?
Upvotes: 1
Views: 62