Apache Http Client 4



  1. Apache Httpclient 405
  2. Apache Httpclient Download
  3. Apache Httpclient 4 Maven
Apache httpclient 405

1. Overview

Apache http client 4.5

In this very quick tutorial, I will show how to get and validate the StatusCode of the HTTP Response using HttpClient 4.

In this quick article, we will discuss step by step how to use Apache HttpClient 4.5 to make an HTTP POST request. The HTTP POST request method requests that the server accepts the entity enclosed in the request as a new subordinate of the web resource identified by the URI. Packages; org.apache.http.auth: Client HTTP authentication APIs. Org.apache.http.auth.params: Deprecated. Org.apache.http.client: Client HTTP communication APIs.

If you want to dig deeper and learn other cool things you can do with the HttpClient – head on over to the main HttpClient tutorial.

Apache Http Client 4

2. Retrieve the Status Code from the Http Response

After sending the Http request – we get back an instance of org.apache.http.HttpResponse – which allows us to access the status line of the response, and implicitly the Status Code:

Using this, we can validate that the code we receive from the server is indeed correct:

Download endpoint security for mac. Notice that we're using the predefined Status Codes also available in the library via org.apache.http.HttpStatus.

Apache Httpclient 405

Apache httpclient 4 maven

3. Conclusion

Apache httpclient 4

See you for mac. This very simple example shows how to retrieve and work with Status Codes with the Apache HttpClient 4.

Apache Httpclient Download

The implementation of all these examples and code snippets can be found in my github project – this is an Eclipse based project, so it should be easy to import and run as it is.

Apache Httpclient 4 Maven

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

>> CHECK OUT THE COURSE