UrlConnection

hi,

I am using UrlConnection.openConnection() to for making a connection of 2 urls. One is Valid and the other one is Invalid, but i am getting the same contents for both rather i want to distinguish or define the (any) content of the Invalid Url. One reason i know is that the web site has created an "error page 404" of it's own so the Invalid url fetches the content of error page, otherwise it would not have fetched any Content. Anyways by which i can fetch different distinguished contents for a Valid and a Invalid Url....... pls help.

Code :

URLConnection con = (URLConnection) new URL(URLName).openConnection();

Object contentObj = con.getContent();

String Content = contentObj.toString();

System.out.println("Content : " + Content);

[787 byte] By [sk_khera] at [2007-10-3 5:26:05]
# 1
Not really no.I don't believe a 404 HTTP response is being sent in the scenario you describe so there is nothing to detect.
cotton.ma at 2007-7-14 23:33:18 > top of Java-index,Java Essentials,Java Programming...
# 2

> Not really no.

>

> I don't believe a 404 HTTP response is being sent in

> the scenario you describe so there is nothing to

> detect.

Yes. I did some looking at headers from sample pages. It seems to depend on the configuration but when you see a special page not found page the server seems to return a 200 OK message instead of 404. So you're sunk to do this easily.

You would have to actually do it by content.

cotton.ma at 2007-7-14 23:33:18 > top of Java-index,Java Essentials,Java Programming...
# 3

Yes. you are right, it gives 200 OK msg for both valid and Invalid URls instead of 404. As you suggested i tried fetching the content, which looks like this..

Valid Url :

http://www.cisco.com/global/DE/events/events_home.shtml

Content : sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@120a47e

Invalid Url :

http://www.cisco.com/global/DE/eve/events_archiv_home.shtml

(eve -can be - events, to form a valid url)

Content :

sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@186c6b2

Code :

URLConnection con = (URLConnection) new URL(URLName).openConnection();

Object contentObj = con.getContent();

String Content = contentObj.toString();

System.out.println("Content : " + Content);

Now, the thing is there is no distinguished Content of 404 Error Page. Different Invalid Urls give different Contents. Do you know anyway by which i can make or cast this content into more readable verision.

Thanks,

Sara

sk_khera at 2007-7-14 23:33:18 > top of Java-index,Java Essentials,Java Programming...