Apache HttpClient Tutorial


This tutorial describes how to use the Apache HttpClient library for accessing HTTP resources. This tutorial is based on Apache HttpClient 4.5+.

HttpClient Overview

As we know that java.net package provides basic functionality for accessing resources via HTTP, it doesn't provide the full flexibility or functionality needed by many applications. HttpClient seeks to fill this void by providing an efficient, up-to-date, and feature-rich package implementing the client side of the most recent HTTP standards and recommendations.

Designed for extension while providing robust support for the base HTTP protocol, HttpClient may be of interest to anyone building HTTP-aware client applications such as web browsers, web service clients, or systems that leverage or extend the HTTP protocol for distributed communication.

Apache HttpClient Usage and Examples

  • Apache HttpClient GET HTTP Request Example
  • In this quick article, we will discuss step by step how to use Apache HttpClient 4.5 to make an Http GET request.

  • Apache HttpClient POST HTTP Request Example
  • 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.

Apache HttpClient Features

  • Standards-based, pure Java, implementation of HTTP versions 1.0 and 1.1
  • Full implementation of all HTTP methods (GET, POST, PUT, DELETE, HEAD, OPTIONS, and TRACE) in an extensible OO framework.
  • Supports encryption with HTTPS (HTTP over SSL) protocol.
  • Transparent connections through HTTP proxies.
  • Tunneled HTTPS connections through HTTP proxies, via the CONNECT method.
  • Basic, Digest, NTLMv1, NTLMv2, NTLM2 Session, SNPNEGO, Kerberos authentication schemes.
  • The plug-in mechanism for custom authentication schemes.
  • Pluggable secure socket factories, making it easier to use third-party solutions
  • Connection management support for use in multi-threaded applications. Supports setting the maximum total connections as well as the maximum connections per host. Detects and closes stale connections.
  • Automatic Cookie handling for reading Set-Cookie: headers from the server and sending them back out in a Cookie: header when appropriate.
  • The plug-in mechanism for custom cookie policies.
  • Request output streams to avoid buffering any content body by streaming directly to the socket to the server.
  • Response input streams to efficiently read the response body by streaming directly from the socket to the server.
  • Persistent connections using KeepAlive in HTTP/1.0 and persistence in HTTP/1.1
  • Direct access to the response code and headers sent by the server.
  • The ability to set connection timeouts.
  • Support for HTTP/1.1 response caching.
  • The source code is freely available under the Apache License.

Useful Links and Resources

References

Comments