Java HttpClient GET request example

In this tutorial we will provide an example of how to use the Apache HttpClient, which is a very popular and stable library to make HTTP requests in Java. It has a vast range of capabilities but in this post we will concentrate on how to make a HttpClient GET request.

Setup

In order to use the HttpClient you will need to include the following dependancy

HttpClient Get request example:

In the example below we are using the HttpClient to make a HTTP GET request, it highlights the following:

  • How to make a GET request (with headers)
  • Handling the response object
  • Inspecting the status code

Output

Running the above code sample produces the following output

In conclusion I hope this post has given you a basic understanding of how to make a HTTP GET request using the apache HttpClient library.

Similar posts

  1. Convert JSON String to java object
  2. Logback configuration examples
  3. Java 8 Streams groupingBy examples

References

  1. Apache HttpClient Documentation

 

 

 

Leave a Reply