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).
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.
I looked for and selected a free proxy, for testing purposes, from a Free Proxy List website. I chose one with a high uptime for my testing routines, but it hasn't worked out so far.
My source 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()));
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:
SocketException: Malformed reply from SOCKS server
When using Proxy.Type.HTTP instead of Proxy.Type.SOCKS, I receive the following error message:
IllegalArgumentException - Invalid Proxy
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.
All help appreciated.