title: HTTP call with Socks 4 proxy
body: <p>I need to call a server using a socks 4 proxy. I am on java version 1.6.</p>
  
  <p>If we use something like this then it treats the SOCKS proxy as version 5.</p>
  
  <pre><code> URL url = new URL("https://www.google.com");  
   URLConnection connection = null;  
   SocketAddress proxySocketAddress1 =  new InetSocketAddress("XXXXXXXXXX", 8081);  
   Proxy proxy = new Proxy(Proxy.Type.SOCKS, proxySocketAddress1);  
   connection = url.openConnection(proxy);  
   connection.setConnectTimeout(150000);  
   connection.connect();  
  </code></pre>
  
  <p>I can setup socks proxy at the system level by doing</p>
  
  <pre><code>// Set SOCKS proxy
  System.getProperties().put( "socksProxyHost","xxxxx");
  System.getProperties().put( "socksProxyPort","1234");
  System.getProperties().put("socksProxyVersion","4");
  </code></pre>
  
  <p>When I do this I am able to reach the server</p>
  
  <pre><code>connection = url.openConnection(); 
  </code></pre>
  
  <p>But my other connections like connections to db, encryption server also goes thru the proxy and fails.</p>
  
  <p>I also tried excluding servers from system proxy but no success.</p>
  
  <pre><code>System.getProperties().put("socksnonProxyHosts","*.net");
  System.getProperties().put("http.nonProxyHosts","*.net"); 
  </code></pre>
  
  <p>Is there any other way I can choose to use SOCKS4 in java 1.6.</p>