tags:

views:

110

answers:

2

I am trying to pull information from another site. When I try and do

URL url = new URL("theSite");
url.getContent();

It throws a Connection refused: connect exception. Does this mean the site will not allow automated connections? Is there another way to get this information?

+1  A: 

See if the site is up and running or not by opening it in the browser. The other thing you might want to check is for any firewall stopping java process to connect.

Teja Kantamneni
The site is up and running. How would I check to see if there is a fire wall.
Lumpy
See Mikes comment about telnet
vickirk
+2  A: 

It can mean several things:

  • The site is having problems and is actively dropping connections (Refused is different from timed out, where no response was received at all)
  • An intermediary may have refused your connection, e.g. a Firewall, although if you can access the site via a browser then this is not likely the case
  • You are using the wrong port, i.e. did you mean http:// when you typed https:// or vice versa?
  • Your browser is accessing the site via a proxy. Check the browsers proxy settings and use them in url.openConnection(Proxy)

telnet is your friend, what happens when you:

telnet thesite 80 [or whatever port you require] GET /URL HTTP/1.0 Host: thesite

Mike
I tried to telnet and got:..Could not open connection to the host, on port 80: Connect failed the site works if I type the address into my browser.
Lumpy
Clearly a firewall problem. Disable/configure it.
BalusC
@Lumpy sounds like your browser is using a proxy. Check the Network settings of the browser. You may need to use url.openConnection(Proxy) to explicitly use a http proxy. http://java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html#openConnection%28java.net.Proxy%29
Mike