public final static void main(final String[] args) throws Exception {

        final ProxyClient proxyClient = new ProxyClient();
        final HttpHost target = new HttpHost("www.yahoo.com", 80);
        final HttpHost proxy = new HttpHost("localhost", 8888);
        final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd".toCharArray());
        try (final Socket socket = proxyClient.tunnel(proxy, target, credentials)) {
            final Writer out = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.ISO_8859_1);
            out.write("GET / HTTP/1.1\r\n");
            out.write("Host: " + target.toHostString() + "\r\n");
            out.write("Agent: whatever\r\n");
            out.write("Connection: close\r\n");
            out.write("\r\n");
            out.flush();
            final BufferedReader in = new BufferedReader(
                    new InputStreamReader(socket.getInputStream(), StandardCharsets.ISO_8859_1));
            String line = null;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
        }
    }
Example code for using {@link ProxyClient} in order to establish a tunnel through an HTTP proxy.
httpclient5/src/test/java/org/apache/hc/client5/http/examples/ProxyTunnelDemo.java