Skip to content

Instantly share code, notes, and snippets.

@cosminpopescu14
Created September 28, 2018 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosminpopescu14/9c8b6de3deeb2ca51270f6902c1fddb4 to your computer and use it in GitHub Desktop.
Save cosminpopescu14/9c8b6de3deeb2ca51270f6902c1fddb4 to your computer and use it in GitHub Desktop.
java 11 features
package com.company;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws InterruptedException, IOException
{
// write your code here
var request = HttpRequest.newBuilder()
.GET()
.uri(URI.create("https://http2.akamai.com/demo/h2_demo_frame.html"))
.build();
var client = HttpClient.newHttpClient();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(response -> {
System.out.println(response.statusCode());
return response;
})
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join(); //don't forget it*/
/*HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());*/
System.out.println(" ".isBlank());
System.out.println("Cosmin ".repeat(2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment