How do I send an Http Post request?

The following code snippet will show you how to send an Http Post request using the Apache HttpComponents. We will send a post request to http://localhost:8080/register. We will include some parameters to the request using the NameValuePair object.

To pass this parameters to the Http Post request we create an instance of UrlEncodedFormEntity and pass the list of NameValuePair as the arguments. And before executing the request we set this entity object to the HttpPost.setEntity() method.

Let’s see the code below: