OkHttp 2.2.x Integration


The Cloudflare SDK supports OkHttp v2.2 and above. To use OkHttp2 with the Cloudflare SDK, use Cloudflare.createOkHttpClient() method. To create an instance of OkHttpClient, use

OkHttpClient client = CFMobile.createOkHttpClient();

instead of using OkHttp as below:

OkHttpClient client = new com.squareup.okhttp.OkHttpClient();

OkHttp UrlConnection

To use Cloudflare SDK with OkHttp UrlConnection, use CFOkUrlFactory to open a connection to an URL. Example:

// Create the URL factory</dt>
CFOkUrlFactory factory = new CFOkUrlFactory();</p>

// Open the URL connection</p>
HttpURLConnection conn = factory.open(new URL("https://img.host.com/img1.jpg"));