How to add headers to OkHttp request interceptor?

前端 未结 10 1535
感情败类
感情败类 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条回答
  •  星月不相逢
    2020-12-01 01:15

    There is yet an another way to add interceptors in your OkHttp3 (latest version as of now) , that is you add the interceptors to your Okhttp builder

    okhttpBuilder.networkInterceptors().add(chain -> {
     //todo add headers etc to your AuthorisedRequest
    
      return chain.proceed(yourAuthorisedRequest);
    });
    

    and finally build your okHttpClient from this builder

    OkHttpClient client = builder.build();
    

提交回复
热议问题