Making HTTP Requests and Working with HTTP Responses - Java Network

Java examples for Network:Http

Introduction

Make use of the HTTP/2 client API and make requests in either a synchronous or asynchronous manner.

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

Related Tutorials