Java HttpClient POST request example

In this tutorial we will continue providing examples of how to use the Apache HttpClient,  we will concentrate on how to make a HttpClient POST request.


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

HttpClient POST request example

In the following example we are using HttpClient to make a HTTP POST request, it shows how to:

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


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 POST request using the apache HttpClient library. Please also visit our other post on how to make other HTTP requests with apache HttpClient.

Similar posts

  1. HttpClient GET request example
  2. How to generate a random number in Java
  3. Java 8 Streams flatmap example
  4. How to convert JSON to Java object


  1. HttpClient Documentation

Leave a Reply