我尝试使用 java 通过一系列代理(不止一个)加载网站。每个请求都应该能够使用另一个链。这是我的第一个快速而肮脏的尝试:
// 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();
作为回应,我收到了这个:
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>
让我们来解决问题。现在我尝试使用 URL/URLConnection 加载页面,以使用 java 包的完整处理和功能。有没有办法将 URL/URLConnection 与代理链一起使用而不是单个代理?
谢谢您的帮助...