Created
June 20, 2020 13:08
-
-
Save SiAust/06aaeb8241836489dd2b5c4bcea59960 to your computer and use it in GitHub Desktop.
Example HTTP connection
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
| class HTTP { | |
| public static void main(String[] args) { | |
| HttpClient client = HttpClient.newBuilder().build(); | |
| HttpRequest request = HttpRequest.newBuilder().GET().uri(URI.create("http://www.bbc.com")).build(); | |
| try { | |
| HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); | |
| System.out.println(response.body()); | |
| } catch (IOException | InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment