First of all we need to add a Maven dependency for Apache Http Client
Apache Http Client Maven dependency
GET HTTP Request
This is how to create a simple GET HTTP request
Here url
is the url of the web service endpoint or the url of the web site page.
For example https://www.google.com
You also can add headers to the request.
For example you want to pretend a browser
or you want to call REST API an get a response in JSON fromat
HTTP client with Apache Http Components
Now you have to create a HTTP client, send a request, get a response and close the HTTP client
response.getEntity().getContent()
We access the response content with response.getEntity().getContent().
If you expect the response body to be a JSON then you can convert that to Java object.
See more about How to convert JSON to Java Object.
Response Code
You also can verify the response code if you need.
All pieces together
You may also find these posts interesting: