Connect Method Example For Proxy Client : Http Client : Apache Common : Java examples (example source code) Organized by topic

Java
C++
PHP
Java Home »  Apache Common   » [  Http Client  ]  Screenshots 
 



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) {}
    }

  }
}
           
       
Download: ConnectMethodExampleForProxyClient.zip   ( 328  K )  
Related examples in the same category
1.  Get Http methods
2.  Get Http client parameters
3.  Execute Http method (post/get)Has Download File
4.  Http Client Simple Demo
5.  Get allowed http methods
6.  Http post method ExampleHas Download File
7.  Basic Authentication Execute JSP MethodHas Download File
8.  Basic Authentication For JSP PageHas Download File
9.  Basic Authentication Get JSP Method Return CodeHas Download File
10.  Get Cookie value and set cookie valueHas Download File
11.  Using Http Client Inside Thread
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.