Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Action.proxies.get(1), 3128));
try{
url = new URL(formattedURL);
connection = url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(
connection));
String line = br.readLine();
while(line !=null){
response.append(line.replace("<br/>","\n").replace("<p>", "\n"));
line = br.readLine();
}
connection.close();
} catch(final Exception e) {
e.printStackTrace();
}
正如你所看到的,我在顶部创建了一个对象,它从我添加数据的HashMap中获取代理。
如何使用代理,以便在与url.openStream()
建立连接时使用代理?