1

I have problem with Retrofit combine with OkHttp Cache and HTTPS. Simply, it doesn't work. When I switch endpoint to non-https version, everything works.

My Retrofit instance:

File cacheDirectory = new File(App.get().getApplicationContext()
    .getCacheDir().getAbsolutePath(), "HttpCache");

try {
    cache = new Cache(cacheDirectory, 10 * 1024 * 1024);
} catch (IOException ioe) {
    Log.w(TAG, ioe);
}

OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setCache(cache);

mInstance = new RestAdapter.Builder()
    .setLogLevel(RestAdapter.LogLevel.HEADERS)
    .setEndpoint("https://....")
    .setClient(new OkClient(okHttpClient))
    .setConverter(new SimpleXMLConverter())
    .setExecutors(Executors.newSingleThreadExecutor(), new MainThreadExecutor())
    .setRequestInterceptor(new RequestInterceptor() {
        @Override
        public void intercept(RequestFacade request) {
            request.addHeader("Cache-Control", "public, max-age=900");
        }
    })
    .build()
    .create(Restu.class);

Response correctly contains header **Cache-Control: public, max-age=900**.

JJD
  • 50,076
  • 60
  • 203
  • 339
Radim Vaculik
  • 559
  • 4
  • 16
  • osri posted a solution to a similar question [here](http://stackoverflow.com/a/23503804/356895). Also take a look [here](https://github.com/square/okhttp/wiki/Recipes#response-caching). – JJD Oct 23 '14 at 13:15

0 Answers0