Reputation: 2653
I am trying to make an HTTP request to the following domain (http2 enabled) on a device running on Android 7.0.
The code i use is as follows:
Request request = new Request.Builder()
.url("https://http2.akamai.com/")
.build();
response = okHttpClient.newCall(request).execute();
statusCode = response.code();
As I notice in the response object, the protocol used by okHttp is HTTP 1.1
The behavior of the okhttp client is random, at one time I was able to see the protocol as h2
but then repeating the request, it kept selecting HTTP 1.1
I am using okhttp v3.5
What am i possibly missing out here ?
Upvotes: 1
Views: 1390
Reputation: 3747
Android has enabled only HTTP/1.1 in its OkHttp.
/**
* Creates an OkHttpClient suitable for creating HttpsURLConnection instances on
* Android.
*/
public static OkUrlFactory createHttpsOkUrlFactory(Proxy proxy) {
...
// Only enable HTTP/1.1 (implies HTTP/1.0). Disable SPDY / HTTP/2.0.
okHttpClient.setProtocols(HTTP_1_1_ONLY);
Upvotes: 1