Programming Tutorials


By: aathishankaran in JSP Tutorials on 2007-02-14  

An HttpClient can be used to send requests and retrieve their responses. An HttpClient is created through a builder. The builder can be used to configure per-client state, like: the preferred protocol version ( HTTP/1.1 or HTTP/2 ), whether to follow redirects, a proxy, an authenticator, etc. Once built, an HttpClient is immutable, and can be used to send multiple requests.

Synchronous Example

   HttpClient client = HttpClient.newBuilder()
        .proxy(ProxySelector.of(new InetSocketAddress("", 80)))
   HttpResponse response = client.send(request, BodyHandlers.ofString());

Asynchronous Example

   HttpRequest request = HttpRequest.newBuilder()
        .header("Content-Type", "application/json")
   client.sendAsync(request, BodyHandlers.ofString())

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in JSP )

Latest Articles (in JSP)