【发布时间】:2016-09-17 16:58:52
【问题描述】:
我正在尝试使用OkHttp 客户端与 HTTP/2 服务器通信。
添加到 Maven POM:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.2.0</version>
</dependency>
这是我的测试代码:
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("https://http2.akamai.com/demo").build();
Response response = client.newCall(request).execute();
System.out.println("Protocol: " + response.protocol());
System.out.println(response.body().string());
但是当我运行它时,它会打印:
协议:http/1.1
和
此浏览器未启用 HTTP/2。
环境:Linux 上的 OpenJDK 8。
您需要额外的东西吗?我看到了一个叫做“ALPN”的东西,但不太明白这个概念。
【问题讨论】: