<div style='background-color: none transparent;'></div>
Home » » Communicate with proxy server to access a website

Communicate with proxy server to access a website

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();
}
}
Share this article :
 
Copyright © 2011. B.Sc B.Tech MCA Ploytechnic Mini,Main Projects | Free Main Projcets Download | MCA |B.tech . All Rights Reserved
Company Info | Contact Us | Privacy policy | Term of use | Widget | Advertise with Us | Site map
Template Modify by Creating Website. Inpire by Darkmatter Rockettheme Proudly powered by Blogger