Skip to content

Instantly share code, notes, and snippets.

@SiAust
Created June 20, 2020 13:08
Show Gist options
  • Save SiAust/06aaeb8241836489dd2b5c4bcea59960 to your computer and use it in GitHub Desktop.
Save SiAust/06aaeb8241836489dd2b5c4bcea59960 to your computer and use it in GitHub Desktop.
Example HTTP connection
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