Skip to content

Instantly share code, notes, and snippets.

@damithadayananda
Created September 18, 2020 12:11
Show Gist options
  • Save damithadayananda/a70797976caeb81261d4f8a7e0b60ce5 to your computer and use it in GitHub Desktop.
Save damithadayananda/a70797976caeb81261d4f8a7e0b60ce5 to your computer and use it in GitHub Desktop.
module main {
requires jdk.incubator.httpclient;
}
public class NewHttpClientDemo {
public void demo() {
try{
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpRequest = HttpRequest
.newBuilder()
.uri(new URI("https://www.geeksforgeeks.org/about/"))
.GET()
.build();
HttpResponse<String> httpResponse = httpClient.send(
httpRequest,
HttpResponse.BodyHandler.asString()
);
System.out.println("Response status:"+httpResponse.statusCode());
System.out.println("Response body:"+httpResponse.body());
}catch (Exception ex){
System.out.println(ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment