OkHttp 3 Integration

To use OkHttp3 with Cloudflare SDK, use CFMobile.createOkHttp3Client() method to create an instance of OkHttpClient.

To create an instance with default settings, use

OkHttpClient client = CFMobile.createOkHttp3Client();

instead of calling OkHttp API as below:

OkHttpClient client = new OkHttpClient();

To create an instance with custom settings use a Builder object as below

   
OkHttpClient.Builder builder = new OkHttpClient.Builder()
    .addInterceptor(new HttpLoggingInterceptor())
    .cache(new Cache(cacheDir, cacheSize));
OkHttpClient client = CFMobile.createOkHttp3Client(builder);</p>

instead of calling OkHttp API as below:

OkHttpClient.Builder builder = new OkHttpClient.Builder()
    .addInterceptor(new HttpLoggingInterceptor())
    .cache(new Cache(cacheDir, cacheSize));
OkHttpClient client = builder.build();</p>