September 2019
Intermediate to advanced
816 pages
18h 47m
English
Creating a body from a file can be accomplished using BodyPublishers.ofFile(), as shown in the following snippet of code:
HttpRequest requestBodyOfFile = HttpRequest.newBuilder() .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofFile(Path.of("user.json"))) .uri(URI.create("https://reqres.in/api/users")) .build();