1,第一步要调用,addQueryParameter
2,第二部要重新new builder
Request.Builder requestBuilder = original.newBuilder()
完整代码如下。
public class HeaderInterceptorimplements Interceptor {
@Override
public Response intercept(Chain chain)throws IOException {
Request original = chain.request();
HttpUrl originalHttpUrl = original.url();
HttpUrl url = originalHttpUrl.newBuilder()
.addQueryParameter("token", ZPreference.pref.getString(CONST.USER_TOKEN,null))
.build();
// Request customization: add request headers
Request.Builder requestBuilder = original.newBuilder()
.url(url);
Request request = requestBuilder.build();
return chain.proceed(request);
}
}
大招在这,还可以这样写@Post请求,然后用@Query注解
网友评论