Creating a body from a file

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();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset