September 2019
Intermediate to advanced
816 pages
18h 47m
English
As we saw in the Setting a request body and Handling response body types sections, the HTTP Client API can send and receive text and binary data (for example, images, videos, and so on).
Downloading a file relies on the following two coordinates:
The following code downloads hibernate-core-5.4.2.Final.jar from the Maven repository in the project classpath:
HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("http://.../hibernate-core-5.4.2.Final.jar")) .build();HttpResponse<Path> response = client.send(request, HttpResponse.BodyHandlers.ofFile( Path.of("hibernate-core-5.4.2.Final.jar"))); ...