How to add headers to OkHttp request interceptor?

前端 未结 10 1538
感情败类
感情败类 2020-12-01 00:24

I have this interceptor that i add to my OkHttp client:

public class RequestTokenInterceptor implements Interceptor {
@Override
public Response intercept(Cha         


        
10条回答
  •  猫巷女王i
    2020-12-01 01:09

    Faced similar issue with other samples, this Kotlin class worked for me

    import okhttp3.Interceptor
    import okhttp3.Response
    
    class CustomInterceptor : Interceptor {
        override fun intercept(chain: Interceptor.Chain) : Response {               
            val request = chain.request().newBuilder()
                .header("x-custom-header", "my-value")
                .build()
            return chain.proceed(request)
        }
    }
    

提交回复
热议问题