HttpUrlConnection or URL to retrieve information

Im working on an application to retrieve information from a website.

The website is www.kingsofchaos.com, a game.

The following code doesn't work, but when I change the url to google, yahoo, or any other website, it works perfectly...

import java.net.*;

import java.io.*;

publicclass URLReader{

publicstaticvoid main(String[] args)throws Exception{

URL koc =new URL("http://www.kingsofchaos.com/");

BufferedReader in =new BufferedReader(

new InputStreamReader(

koc.openStream()));

String inputLine;

while ((inputLine = in.readLine()) !=null)

System.out.println(inputLine);

in.close();

}

}

[1259 byte] By [tylerrubya] at [2007-11-26 12:52:01]
# 1
This site may need proper setting of "User-Agent" header
AjaySingh516a at 2007-7-7 16:40:29 > top of Java-index,Archived Forums,Socket Programming...
# 2
Not sure how I will go about doing that, could somebody give me an example?I've used one that uses user-agent before I think, with all the Mozilla headers and it also didn't work...
tylerrubya at 2007-7-7 16:40:29 > top of Java-index,Archived Forums,Socket Programming...
# 3

You can set the headers as,

URLConnection connection = url.openConnection();

connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible;

MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR

2.0.50727)"); // Will set IE user agent

AjaySingh516a at 2007-7-7 16:40:29 > top of Java-index,Archived Forums,Socket Programming...
# 4
I tried what you posted but had a few errors, is there anyway you can give me a full script that retrieves the html source from www.kingsofchaos.com
tylerrubya at 2007-7-7 16:40:29 > top of Java-index,Archived Forums,Socket Programming...
# 5

this code works for me:

URL koc = new URL("http://www.kingsofchaos.com/");

URLConnection connection = koc.openConnection();

connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible;

MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR

2.0.50727)"); // Will set IE user agent

BufferedReader in = new BufferedReader(new

InputStreamReader(connection.getInputStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)

System.out.println(inputLine);

in.close();

AjaySingh516a at 2007-7-7 16:40:29 > top of Java-index,Archived Forums,Socket Programming...
# 6
Yep that worked. Thanks a lot, I appreciate it..
tylerrubya at 2007-7-7 16:40:29 > top of Java-index,Archived Forums,Socket Programming...