我测试一个支持HTTP / 2,like this的站点,
我尝试使用okhttp发送请求:
我尝试使用okhttp发送请求:
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()); } });
在日志中我得到这样的东西:
OkHttp-Selected-Protocol: http/1.1
okhttpClient选择使用http / 1.1,如何强制使用HTTP / 2?