我已经构建了OkHttpClient
的实例。如何添加拦截器? (我也在使用Retrofit)
我希望将授权令牌添加到其中。我目前收到以下错误:
Error creating evaluation class loader: com.intellij.debugger.engine.evaluation.EvaluateException: Method threw 'java.lang.NullPointerException' exception.
java.lang.NullPointerException: parentLoader == null && !nullAllowed
当我这样做时:
okHttpClient = okHttpClient.newBuilder().addNetworkInterceptor(new Interceptor()
{
@Override
public Response intercept(final Chain chain) throws IOException
{
final Request request = chain.request();
Request newRequest;
newRequest = request.newBuilder()
.addHeader(AUTHORIZATION_HEADER, String.format("Bearer %s", "Bob"))
.build();
return chain.proceed(newRequest);
}
}).build();