March 2019
Intermediate to advanced
242 pages
6h 21m
English
HttpClient can receive a response from a server in either a synchronous or asynchronous manner. To receive a response synchronously, use the HttpClient method, send(). This request will block the thread until the response is completely received.
The following code connects to Oracle's web server that hosts the API documentation of the HttpClient class, using a GET request sent synchronously:
class SyncGetHTML {
public static void main(String args[]) throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://docs.oracle.com/en/java/javase /11/docs/api/java.net.http/java/net/http/HttpClient.html")) .build(); HttpResponse<String> ...Read now
Unlock full access