在一个项目的很多个retorfit接口中,都要带上一些公共的参数用于日志记录、统计分析等,比如设备信息、版本号、包名等参数。
除了在每一个retrofit接口上手动写一遍以外,有没有封装型的写法?
人生最曼妙的风景,竟是内心的淡定与从容!
It seems that you can customize OkhttpClient’s interceptor
You can add a unified header
builder.addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException, java.io.IOException { Request request = chain.request().newBuilder() .addHeader("Source", "android") .addHeader("Accept", "application/json,text/javascript,*/*") .build(); return chain.proceed(request); } });
Everything you need is here: retrofit package
Interceptor is what you need.
It seems that you can customize OkhttpClient’s interceptor
You can add a unified header
Everything you need is here: retrofit package
Interceptor is what you need.