2015-08-06 13 views
10

sto testando un sito che supporta HTTP/2, like this, e cerco di usare okhttp per inviare la richiesta:Come utilizzare http/2 con Okhttp su dispositivi Android?

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()); 
    } 
}); 

Nel registro ho ottenuto qualcosa di simile:

OkHttp-Selected-Protocol: http/1.1 

okhttpClient ha scelto di utilizzare http/1.1, come posso forzare l'uso di HTTP/2?

+0

Ho trovato [questo] (https://github.com/square/okhttp/issues/1455#issuecomment-75818950), Si riduce il supporto okhttp h2-16 e successive. – Zack

+0

quale okHttp stai usando? in base a questo https://publicobject.com/2015/03/17/okhttp-2-3-has-http2/ versione 2.3 hanno il http/2 – Yazan

+0

@Yazan Io uso la versione 2.4.0 – Zack

risposta

3

Okhttp 2.5+ supporta solo http/2 sopra 5.0+ tramite ALPN.

ma è possibile modificare il codice sorgente per supportare http/2 sopra 4.0+ tramite NPN.

Problemi correlati