URL : Connection timed out error
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   champion_boliao
Posted On:   Friday, November 15, 2002 12:38 AM

hi, i am a newbie in java and i just want to implement a very simple application to read the content from a webpage. below is my code try { url = new URL("http://www.nba.com"); System.out.println("getContent...."); InputStream is = url.openStream(); dataInput = new BufferedReader(new InputStreamReader(input)); while ((line = dataInput.readLine()) != null) { buffer.append(line); buffer.append(' '); } System.out.println("ok"); catch (Exception ex) { .... snip.. } the problem is, during runtime, the process stuck at the "getcontent...&   More>>

hi,



i am a newbie in java and i just want to implement a very simple application to read the content from a webpage. below is my code




			
try {
url = new URL("http://www.nba.com");
System.out.println("getContent....");
InputStream is = url.openStream();
dataInput = new BufferedReader(new InputStreamReader(input));
while ((line = dataInput.readLine()) != null)
{
buffer.append(line);
buffer.append('
');
}
System.out.println("ok");
catch (Exception ex)
{
.... snip..
}


the problem is, during runtime, the process stuck at the "getcontent..." for a while then it reports Connection timed out error.

of course, i run this from a PC with internet connection. something must be wrong.

can someone please enlighten me.

thanks alot.    <<Less

Re: URL : Connection timed out error

Posted By:   Jorgen_Nordqvist  
Posted On:   Monday, November 18, 2002 02:27 PM

Change the url.openStream() line to:


conn = (HttpURLConnection) url.openConnection();
dataInput = new BufferedReader(new InputStreamReader(conn.getInputStream()));


and it might just do the trick.

Jorgen

About | Sitemap | Contact