Hey aibtus - Here is a full code example:
import java.net.*;
import java.io.*;
class httpconnect {
public static void main(String[] args) throws Exception {
URL url = new URL("http://www.google.co.uk/");
URLConnection spoof = url.openConnection();
spoof.setRequestProperty(
"User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
String strLine = "";
while ((strLine = in.readLine()) != null) {
System.out.println(strLine);
}
in.close();
}
}
Note the extra bit of code:
spoof.setRequestProperty(
"User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
Websites like Google block connections to their site from programs other than web browsers. With this bit of code you can trick sites like these into thinking the connection is coming from a web browser. Very handy!
If you wish to surf through a proxy server then you can also add this code to the top:
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyPort", "80");
System.getProperties().put("proxyHost", "my.proxyserver.co.uk");