Source Code : Connect Method Example For Proxy Client

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Connect Method Example For Proxy Client

import org.apache.commons.httpclient.ProxyClient;
import org.apache.commons.httpclient.ConnectMethod;
import org.apache.commons.httpclient.ProxyClient.ConnectResponse;

import java.net.Socket;

public class ConnectMethodExampleForProxyClient {

  public static void main(String args[]) {

    ProxyClient client = new ProxyClient();
    client.getParams().setParameter("http.useragent","Proxy Test Client");

    client.getHostConfiguration().setHost("www.somehost.com");
    client.getHostConfiguration().setProxy("localproxyaddress",80);

    Socket socket = null;

    try{
      ConnectResponse response = client.connect();
      socket = response.getSocket();
      if(socket == null) {
        ConnectMethod method = response.getConnectMethod();
        System.err.println("Socket not created: " + method.getStatusLine());
      }
      // do something
    } catch (Exception e) {
      System.err.println(e);
    } finally {
      if(socket != null) 
          try { 
              socket.close(); 
          } catch (Exception fe) {}
    }

  }
}
           
       

Thank with us