10
Ich teste eine Website, die HTTP unterstützt/2, like this, und ich versuche zu verwenden okhttp die Anfrage zu senden:Wie verwendet man http/2 mit Okhttp auf Android-Geräten?
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder()
.url("https://www.google.it")
.build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Response response) throws IOException {
Log.d("TestHttp", "OkHttp-Selected-Protocol: " + response.header("OkHttp-Selected-Protocol"));
Log.d("TestHttp", "Response code is " + response.code());
}
});
Im Protokoll habe ich so etwas wie dieses:
OkHttp-Selected-Protocol: http/1.1
Der okhttpClient wählte http/1.1, wie kann ich die Verwendung von HTTP/2 erzwingen?
Ich fand [this] (https://github.com/square/okhttp/issues/1455#issuecomment-75818950), Es scheint, dass die okhttp Unterstützung h2-16 und höher. – Zack
welche okHttp verwendest du? basierend auf diesem https://publicobject.com/2015/03/17/okhttp-2-3-has-http2/ Version 2.3 haben die http/2 – Yazan
@Yazan ich benutze Version 2.4.0 – Zack