我正在测试一个支持HTTP/2的网站,像这样,并尝试使用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?