图像管道使用HttpURLConnection
与 Android 捆绑的网络库。
HttpURLConnection connection.setRequestProperty("Charset", "utf-8");
Fresco:如何将 RequestProperty 添加到 ImageRequestBuilder?
图像管道使用HttpURLConnection
与 Android 捆绑的网络库。
HttpURLConnection connection.setRequestProperty("Charset", "utf-8");
Fresco:如何将 RequestProperty 添加到 ImageRequestBuilder?
如果您在谈论请求标头,这是我在我的应用程序中所做的
DiskCacheConfig mainDiskCacheConfig = DiskCacheConfig.newBuilder()
.setBaseDirectoryPath(sContext.getCacheDir())
.setBaseDirectoryName("cache")
.setMaxCacheSize(1024 * 1024 * 1024) // max cache size
.setMaxCacheSizeOnLowDiskSpace(50 * 1024 * 1024) // for low disk cache
.setMaxCacheSizeOnVeryLowDiskSpace(10 * 1024 * 1024) // for
.build();
OkHttpClient client = new OkHttpClient();
client.interceptors().add(new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
com.squareup.okhttp.Request originalRequest = chain.request(); //Current Request
com.squareup.okhttp.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(Constant.AUTH_HEADER, BackgroundService.getAuthenticationHeader())
.addHeader(Constant.X_USER_ID, Wrapper.getInstance().getUserId())
.addHeader(Constant.X_DEVICE_KEY, DeviceUtils.getDeviceDetails(App.this).getAndroid_id())
.addHeader(Constant.X_ACCEPT_LANGUAGE, Constant.ACCEPT_LANGUAGE_ENGLISH)
.build();
Response response = chain.proceed((requestWithToken != null ? requestWithToken : originalRequest)); //proceed with the request and get the response
if (response != null && response.code() != HttpURLConnection.HTTP_OK) {
response.body().close();
}
return response;
}
});
ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(this, client)
.setMainDiskCacheConfig(mainDiskCacheConfig)
.build();
Fresco.initialize(this, config);