March 2019
Intermediate to advanced
242 pages
6h 21m
English
You can create an instance of HttpClient in two ways: by using its static getHttpClient() method, or by using the newBuilder() method (this follows the builder pattern).
The static getHttpClient() method returns a HttpClient instance with basic or default settings, as follows:
HttpClient client = HttpClient.newHttpClient();
To add custom settings, you can use its newBuilder() method, which follows the builder design pattern and calls relevant methods. Let's start with a basic version, and then add to it. For example, you can use the following code to set the HTTP version as 2:
HttpClient client = HttpClient.builder().
.version(Version.HTTP_2)
.build();
Read now
Unlock full access