Skip to content

Instantly share code, notes, and snippets.

@NikolayGorshkov
Created August 2, 2019 14:35
Show Gist options
  • Save NikolayGorshkov/fcd3c0700a15b6b36ec74b3df55e0343 to your computer and use it in GitHub Desktop.
Save NikolayGorshkov/fcd3c0700a15b6b36ec74b3df55e0343 to your computer and use it in GitHub Desktop.
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpClient.Redirect;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse.BodyHandlers;
public class HttpClientExample {
public static void main(String[] args) throws Exception {
String response =
HttpClient.newBuilder()
.followRedirects(Redirect.NORMAL)
.build()
.send(
HttpRequest.newBuilder()
.GET().uri(new URI("https://google.com/"))
.build(),
BodyHandlers.ofString())
.body();
System.out.println(response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment