Is HTTP proxy supported when using java.net.Socket instead of URLConnection? I need to use Socket so I can use setSoTimeout() for non-blocking reads. When I switched from URLConnection to Socket, the proxyHost and proxyPort system properties had no effect.

Tim Rohaly

HTTP proxies perform a function specific to the HTTP protocol. The HTTP protocol is implemented in whole by the class HttpURLConnection - it is in this implementation that the system properties relating to proxies are read and used. java.net.Socket in particular does not take these properties into account. Instead, Socket has support for general SOCKS proxies. The differences between these two types of proxies is described in http://www.jguru.com/jguru/faq/view.jsp?EID=227532.

If you are reimplementing the HTTP protocol using sockets rather than HttpURLConnection, you will have to reimplement the code to proxy HTTP as well. Or, better yet, use a freely-available package such as HTTPClient which reimplements this for you - you can then just tweak that code to your liking. HTTPClient can be found at http://www.innovation.ch/java/HTTPClient/.