android okhttp加公共参数_Android Retrofit通过OkHttp添加Interceptor拦截器设置Get请求公共参数...

pubic Retrofit getRetrofit() {

OkHttpClient httpClient = new OkHttpClient.Builder()

.addInterceptor(new Interceptor() {

@Override

public Response intercept(Chain chain) throws IOException {

Request request = chain.request();

if ("GET".equals(request.method())) {

HttpUrl httpUrl = request.url().newBuilder()

.addQueryParameter("version", "1.0.0")

.addQueryParameter("appkey","yeyuanxinyi")

.addQueryParameter("timestamp", String.valueOf(System.currentTimeMillis()))

.build();

request = request.newBuilder().url(httpUrl).build();

}

return chain.proceed(request);

}

})

.build();

return new Retrofit.Builder()

.client(httpClient)

.addConverterFactory(GsonConverterFactory.create())

.addCallAdapterFactory(RxJava2CallAdapterFactory.create())

.baseUrl(getBaseUrl())

.build();

}

你可能感兴趣的:(android,okhttp加公共参数)