HttpClient Examples

  • Direct request

    This example demonstrates how to send an HTTP request directly.

  • Request via a proxy

    This example demonstrates how to send an HTTP request via a proxy.

  • Connection management

    This example demonstrates the recommended way of using API to make sure the underlying connection gets released back to the connection manager.

  • Abort method

    This example demonstrates how to abort an HTTP request before its normal completion.

  • Client authentication

    This example uses HttpClient to execute an HTTP request against a target site that requires user authentication.

  • Proxy authentication

    A simple example showing execution of an HTTP request over a secure connection tunneled through an authenticating proxy.

  • Chunk encoded POST

    This example shows how to stream out a request entity using chunk encoding.

  • Custom execution context

    This example demonstrates the use of a local HTTP context populated custom attributes.

  • Form based logon

    This example demonstrates how HttpClient can be used to perform form-based logon.

  • Threaded request execution

    An example that executes HTTP requests from multiple worker threads.

  • Custom SSL context

    This example demonstrates how to create secure connections with a custom SSL context.

  • Custom protocol interceptors

    This example shows the use of protocol interceptors to transparently modify properties of HTTP messages sent / received by the HTTP client.

    In this particular case HTTP client is made capable of transparent content GZIP compression by adding two protocol interceptors: a request interceptor that adds 'Accept-Encoding: gzip' header to all outgoing requests and a response interceptor that automatically expands compressed response entities by wrapping them with a uncompressing decorator class. The use of protocol interceptors makes content compression completely transparent to the consumer of the HttpClient interface.