Created
September 18, 2020 12:11
-
-
Save damithadayananda/a70797976caeb81261d4f8a7e0b60ce5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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