0
因此,一些圖像I請求需要被添加Freso:我如何設置OK Http客戶端?
我使用改造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+"
在這一天結束時,我只需要設置認證頭的圖像請求
感謝閱讀
我認爲你正在尋找此:http://frescolib.org/docs/using-other-network-layers.html –
完美,謝謝。 –