java.net.ConnectException: Connection refused: connect
807597Feb 21 2005 — edited Oct 3 2008I have a problem with URL in Java.
here is my program which i found in the Java Tutorial on Networking basics:
import java.io.*;
import java.net.*;
public class UrlRead
{
public static void main(String[] args) throws Exception
{
URL aURL = new URL("http:/www.yahoo.com/");
BufferedReader in = new BufferedReader(new InputStreamReader(aURL.openStream()));
String str;
while((str=in.readLine())!= null)
System.out.println(str);
in.close();
}
}
It compiles fine, but when i run it it gives me the following error:
Exception in thread "main" java.net.ConnectException: Connection refused: connec
t
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:426)
at java.net.Socket.connect(Socket.java:376)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:386)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:602)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:303)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:264)
at sun.net.www.http.HttpClient.New(HttpClient.java:336)
at sun.net.www.http.HttpClient.New(HttpClient.java:317)
at sun.net.www.http.HttpClient.New(HttpClient.java:312)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
ction.java:481)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
.java:472)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:574)
at java.net.URL.openStream(URL.java:960)
at UrlRead.main(UrlRead.java:14)
In the tutorial it sez:
Platform-Specific Details: Setting the Proxy Host
You can set the proxy host through the command line. Depending on your network configuration, you might also need to set the proxy port. If necessary, ask your system administrator for the name of the proxy host on your network.
UNIX
java -Dhttp.proxyHost=proxyhost
[-Dhttp.proxyPort=portNumber] URLReader
DOS shell (Windows 95/NT)
java -Dhttp.proxyHost=proxyhost
[-Dhttp.proxyPort=portNumber] URLReader
so, i tried the following :
java -Dhttp.proxyHost=10.236.133.78 UrlRead
but it didnt work ; I also tried using portnumber =80....
still the same error.....
Can anyone , please help me out here?