tags:

views:

39

answers:

4

hi all,

i'm trying to read the text from a website using the Java URL input stream as follows -

URL u = new URL(str);
br3 = new BufferedReader(new InputStreamReader(u.openStream()));
while(true)  
 System.out.println(br3.readLine());

this seems to work fine for most websites, but for some url shortening services like linkbee, the object draws a blank. e.g. http://linkbee.com/FUAKF, i can view the source code using an explorer, however i repeatedly get nulls when i use the above code.

+2  A: 

It's because those sites are just redirection services. How are you handling redirects? (a redirect has a Location: header, but no body)

barrycarter
A: 

use a http library like commons:httpclient, the method getResponseBodyAsStream follows redirects automatically

seanizer
A: 

Barry is correct.

I just wanted to add that for certain websites there also could be javascript that could redirect you to a different page. Something like this:

<script type="text/javascript"> <!-- window.location = "http://www.google.com/" //--> </script>

But in your situation it would be the headers redirecting you based on the fact you are getting nulls back. Just thought you might want to watch out for the javascript thing too.

The Real Diel
A: 

it's true that it is a redirection service, however i do not require actually following the redirection, i merely need to extract the url that it redirects to - which can found within the source code of the redirection website itself (which in the given case, is at line 81, input type='hidden' id='urlholder' value='http://www.megaupload.com/?d=02EBRUTT'.

regardless i don't think the stream should be giving me a complete blank unless it doesn't read head, only body?

Roio