I try to load websites over a chain of proxies(more then one) with java. Every Request should be able to use another chain. Here my first quick and dirty try:
// My proxies and there ports marked with pIP1 pPort1, pIP2 pPort2...
Socket socket = new Socket(pIP1, pPort1);
OutputStream out = socket.getOutputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String connectOverProxy1ToProxy2 = "CONNECT " + pIP2 + ":" + pPort2 + " HTTP/1.1\n\n";
String connectHost = "GET http://stackoverflow.com/ HTTP/1.1\n\n";
out.write((connectOverProxy1ToProxy2 + connectHost).getBytes());
out.flush();
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
out.close();
in.close();
As response i recived this:
HTTP/1.0 200 Connection established
Proxy-agent: tinyproxy/1.8.3
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: public, max-age=30
Expires: Mon, 08 Apr 2013 11:42:08 GMT
X-Frame-Options: SAMEORIGIN
Date: Mon, 08 Apr 2013 11:41:36 GMT
Last-Modified: Mon, 08 Apr 2013 11:41:08 GMT
Vary: *
Content-Length: 182825
<!DOCTYPE html>
<html>
[..]
</html>
Lets come to the problem. Now I try to load the page with URL/URLConnection to use the full handling and functinality of the java-packages. Is there a way to use URL/URLConnection with a chain of proxies instead a single proxy?
Thanks for the help...