• Post Reply Bookmark Topic Watch Topic
  • New Topic

connecting to URL  RSS feed

 
Ruud Steeghs
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In one of the Java tutorials there's an example (see below) of how to connect to a URL and read its contents.
Usually this code works, but in my project, it does not!!! The URL.openStream() throws an Exception. What could be the problem? Could there be some network restrictions on the location where I'm working?
Cheers,
-Ruud.

import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.interpolis.nl/");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahoo.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you drop the details of the exception here?
It could be any one of a number of things (are you using a proxy, are you IP blocked etc) and it isn't enough just to say "my code doesn't work"
ta,
Dave.
 
Ruud Steeghs
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my case a java.net.SocketException is thrown with the following message: no further information (code=10051)
I'm behind a firewall and when I try to connect to a URL that's in my intranet, the code does work.
Sorry for not being clear enough the first time.
Cheers,
Ruud.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!