SHARE
TWEET

Untitled

a guest Jun 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var client = HttpClient.newHttpClient();
  2.  
  3.     var httpRequest = HttpRequest.newBuilder()
  4.             .uri(new URI(apiUrl))
  5.             .version(HttpClient.Version.HTTP_2)
  6.             .header("Content-Type", "application/json")
  7.             .header("Authorization", "Basic " + DatatypeConverter.printBase64Binary(userPassword.getBytes()))
  8.             .POST(HttpRequest.BodyPublishers.ofByteArray(request))
  9.             .build();
  10.  
  11.     HttpResponse.BodyHandler<String> bodyHandler = HttpResponse.BodyHandlers.ofString();
  12.  
  13.     CompletableFuture<HttpResponse<String>> future = client.sendAsync(httpRequest, bodyHandler);
  14.     future.thenApply(HttpResponse::body)
  15.             .thenAccept(System.out::println)
  16.             .join();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top