private void establishConnection() {
try {
URL url = new URL("http://www.javagalaxy.com");
//change this to valid proxy server and proxy server port
InetSocketAddress isa = new InetSocketAddress("192.168.0.12", 8080);
Proxy proxy = new Proxy(Proxy.Type.HTTP, isa);
URLConnection urlConnection = url.openConnection(proxy);
urlConnection.connect();
InputStream inStream = urlConnection.getInputStream();
BufferedInputStream binStream = new BufferedInputStream(inStream);
int i = 0;
byte[] b = new byte[128];
File file = new File("index.html");
FileOutputStream fout = new FileOutputStream(file);
while (i != -1) {
i = binStream.read(b);
if (i > 0)
fout.write(b);
System.out.print(b);
}
fout.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Home »
» Communicate with proxy server to access a website