Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public CompletableFuture<String> getFoodAsync(HttpClient client, HttpRequest request) {
- return client.sendAsync(request, BodyHandlers.ofString()).thenApply(HttpResponse::body);
- }
- .....
- URI uri = new URI(totalPath);
- HttpRequest request = HttpRequest.newBuilder(uri).build();
- HttpClient client = HttpClient.newHttpClient();
- var rand = new randomTest();
- CompletableFuture<String> foodInfo = rand.getFoodAsync(client, request);
- foodInfo.join();
- String json = foodInfo.get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement