Tuesday, December 27, 2011

Get HTTP Proxy


<< Previous Table of Categories Next >>


 
    /**
     * Feel free to copy and use this.
     * If you have any comments or better solutions, please paste on my blog: 
     * http://blog.yanmingyu.com or email me feedback.andrewyu@gmail.com
    */

  public Proxy getProxy(String proxyUrl)
  {
      Proxy proxy = Proxy.NO_PROXY;
      try
      {
        if (proxyUrl != null && proxyUrl.length() > 0)
        {
          URL url = new URL(proxyUrl);
          SocketAddress socketAddress = new InetSocketAddress(url.getHost(), url.getPort());
          proxy = new Proxy(Proxy.Type.HTTP, socketAddress);
        }
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
      return proxy;
  }

No comments:

Post a Comment