title: Java - using Socket with Proxy
body: <p>I am using sockets to connect to websites and APIs via HTTP (I know, this could be done easier with the URL class, but I had some reasons for choosing this way).</p>
  
  <p>Now I want to implement a privacy feature, and so all the connections should be redirected through a proxy. But I am running into problems doing that.</p>
  
  <p>I looked for and selected a free proxy, for testing purposes, from a <a href="http://www.freeproxylists.net/" rel="nofollow">Free Proxy List</a> website. I chose one with a high uptime for my testing routines, but it hasn't worked out so far.</p>
  
  <p>My source code:</p>
  
  <pre><code>URL url = new URL("someurl");
  InetSocketAddress address = new InetSocketAddress("202.77.110.22", 8080); 
  java.net.Proxy javaProxy = new Proxy(Proxy.Type.SOCKS, address);
  Socket server = new Socket(javaProxy);
  server.connect(new InetSocketAddress(url.getHost(), url.getPort()));
  </code></pre>
  
  <p>I want to connect to the URL via the proxy "202.77.110.22:8080". If I execute the code using Eclipse, I have to wait approximately five minutes and then receive the following error: </p>
  
  <blockquote>
    <p>SocketException: Malformed reply from SOCKS server</p>
  </blockquote>
  
  <p>When using Proxy.Type.HTTP instead of Proxy.Type.SOCKS, I receive the following error message: </p>
  
  <blockquote>
    <p>IllegalArgumentException - Invalid Proxy</p>
  </blockquote>
  
  <p>I know that (forms of) this question have already been asked on Stackoverflow, but none of the answers have helped me. Maybe I chose an unsupported proxy? It works while testing it using Apache HttpComponents.</p>
  
  <p>All help appreciated.</p>