*/
public class ProxyTunnelDemo {
public static void main(String[] args) throws Exception {
ProxyClient proxyclient = new ProxyClient();
// set the host the proxy should create a connection to
//
// Note: By default port 80 will be used. Some proxies only allow conections
// to ports 443 and 8443. This is because the HTTP CONNECT method was intented
// to be used for tunneling HTTPS.
proxyclient.getHostConfiguration().setHost("www.yahoo.com");
// set the proxy host and port
proxyclient.getHostConfiguration().setProxy("10.0.1.1", 3128);
// set the proxy credentials, only necessary for authenticating proxies
proxyclient.getState().setProxyCredentials(
new AuthScope("10.0.1.1", 3128, null),
new UsernamePasswordCredentials("proxy", "proxy"));
// create the socket
ProxyClient.ConnectResponse response = proxyclient.connect();
if (response.getSocket() != null) {
Socket socket = response.getSocket();
try {
// go ahead and do an HTTP GET using the socket