public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
long t1 = System.nanoTime();
//add header params
request = request.newBuilder().addHeader("header", "header").build();
Log.d("retrofit request", request.url().toString());
Response response = chain.proceed(request);
long t2 = System.nanoTime();
String bodyString = response.body().string();
Log.d("retrofit response",
"request time " + (t2 - t1) / 1e6d + "ms\n" +
"request url " + response.request().url().toString() + "\n"
+ "response body " + bodyString
);
return response.newBuilder()
.body(ResponseBody.create(response.body().contentType(), bodyString))
.build();
}
如何为所有请求添加get / post params?拦截可以只添加标题参数,我使用改造2.0 beta-1?有没有解决方案?
答案 0 :(得分:0)
检查一下(Retrofit beta-4):
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
HttpUrl url = originalRequest.url().newBuilder().addQueryParameter("id", "value").build();
return chain.proceed(originalRequest.newBuilder().url(url).build());
}