利用HTTP / 2客户端API并以同步或异步方式发出请求。
try {// 来自 时代Java公众号 - N o w J a v a . c o m HttpResponse resp = HttpRequest .create(new URI("http://www.apress.com/us/")).GET().response(); int statusCode = resp.statusCode(); String body = resp.body(HttpResponse.asString()); System.out.println("Status Code: " + statusCode); // Do something with body text } catch (URISyntaxException | IOException | InterruptedException ex) { ex.printStackTrace();; }