O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

There are two main steps in making an HTTP call to a URL:

  1. Creating an HTTP client to initiate the call.
  2. Setting up the destination URL, required HTTP headers, and the HTTP method type, that is, GETPOST, or PUT.

The Java HTTP Client API provides a builder class, jdk.incubator.http.HttpClient.Builder, which can be used to build an instance of jdk.incubator.http.HttpClient at the same time, making use of the builder APIs to set up jdk.incubator.http.HttpClient. The following code snippet shows how to get an instance of jdk.incubator.http.HttpClient with the default configuration:

HttpClient client = HttpClient.newHttpClient();

The following code snippet uses the builder to configure and then create an instance of jdk.incubator.http.HttpClient ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required