android - Retrofit 包含公共的请求参数怎么写
黄舟
黄舟 2017-04-17 17:53:31
0
4
562

在一个项目的很多个retorfit接口中,都要带上一些公共的参数用于日志记录、统计分析等,比如设备信息、版本号、包名等参数。

除了在每一个retrofit接口上手动写一遍以外,有没有封装型的写法?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
Peter_Zhu

It seems that you can customize OkhttpClient’s interceptor

PHPzhong

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template