所以我要求的一些图像需要添加身份验证标头
我正在使用 Retrofit 2.0,它具有带有拦截器的 OkHttp 客户端,可将用户令牌添加到每个请求的标头
okHttpClient.interceptors().add(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request(); //Current Request
Request requestWithToken = null; //The request with the access token which we will use if we have one instead of the original
requestWithToken = originalRequest.newBuilder().addHeader(Constants.UrlParamConstants.HEADER_AUTHORIZATION,String.format(Constants.UrlParamConstants.HEADER_AUTHORIZATION_VALUE, MyApplication.getInstance().getUser().getApiToken())).build();
Response response = chain.proceed((requestWithToken != null ? requestWithToken : originalRequest)); //proceed with the request and get the response
return response;
}
});
我想知道如何为 Fresco 库设置相同的 okHttp 客户端实例。
我知道您需要添加此依赖项才能将 OkHttp 与 Fresco 一起使用,但是如何设置客户端呢?
compile "com.facebook.fresco:imagepipeline-okhttp:0.8.0+"
归根结底,我只需要为图像请求设置身份验证标头
谢谢阅读