I want to make a request via a proxy. This, with no proxy, works fine:
Socket sock = new Socket("example.com", 80);
OutputStream oStream = sock.getOutputStream();
//Writing headers to send to the proxy
String request = rType + " " + uri + " HTTP/1.0";
oStream.write(request.getBytes());
oStream.write(endOfLine.getBytes());
String cmd = "host: "+ header.get("host");
oStream.write(cmd.getBytes());
oStream.write(endOfLine.getBytes());
System.out.println(cmd);
//............................
But this, with a proxy, isn't working well, it hangs:
Proxy prx = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("my proxy ip address", 1234)); // predefined ip and port
sock = new Socket(prx);
sock.connect(new InetSocketAddress("example.com", 80)); //hangs here
oStream = sock.getOutputStream();
//............................
What's up with that?
As @MrSimpleMind already stated: Use
Proxy.Type.HTTP
instead ofProxy.Type.SOCKS
.