Android Retrofit通过OkHttp添加Interceptor拦截器设置Get请求公共参数 发表于 2019-07-06 | 阅读次数: | 本文字数: 1.2k | 阅读时长 ≈ 1 分钟 12345678910111213141516171819202122232425pubic 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();}