Package modernfeatures.java11
Class HttpClientDemo
java.lang.Object
modernfeatures.java11.HttpClientDemo
Demonstrates usage of Java 11's
HttpClient
for HTTP requests.
This example covers:
- Synchronous HTTP GET requests using
HttpClient.send()
- Asynchronous HTTP GET requests using
HttpClient.sendAsync()
The class shows how to:
- Build and send a synchronous request, and process the response.
- Build and send an asynchronous request, register a callback to handle the response, and ensure the program waits for the async operation to complete.
Usage: java modernfeatures.java11.HttpClientDemo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Main method demonstrating: How to perform a synchronous HTTP GET request and print the response. How to perform an asynchronous HTTP GET request, register a callback for the response, and wait for the asynchronous operation to finish.
-
Constructor Details
-
HttpClientDemo
public HttpClientDemo()
-
-
Method Details
-
main
Main method demonstrating:- How to perform a synchronous HTTP GET request and print the response.
- How to perform an asynchronous HTTP GET request, register a callback for the response, and wait for the asynchronous operation to finish.
- Parameters:
args
- command-line arguments (not used)- Throws:
Exception
- if an error occurs during HTTP operations
-