This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes java.net.ConnectException: Connection refused: connect Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "java.net.ConnectException: Connection refused: connect" Watch "java.net.ConnectException: Connection refused: connect" New topic
Author

java.net.ConnectException: Connection refused: connect

Ashwini Kale
Greenhorn

Joined: May 15, 2008
Posts: 1
Hi
I am trying to open a web page using HttpURLConnection. I was getting ConnectExecption. I thought may be this is because I am behind a proxy.

I tried using a couple of approaches.. some of them from a thread on javaranch itself.

This is the code that i tried using... i provided proper values to
systemSettings.put("http.proxyHost","myproxy.com") ;
systemSettings.put("http.proxyPort", "80") ;

Still m left with the refused connection.

Please help!! Thanks

import java.util.*;
import java.io.*;
import java.net.*;

public class crawler {
public static void main(String args[]) {

try {

//First set the Proxy settings on the System
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost","myproxy.com") ;
systemSettings.put("http.proxyPort", "80") ;

URL yahoo = new URL("http://www.yahoo.com");
HttpURLConnection con = (HttpURLConnection) yahoo.openConnection();

BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));

String inputLine;

while ( (inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
catch (MalformedURLException me) {
System.out.println("MalformedURLException: " + me);
me.printStackTrace();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1220

Hi Ashwini,

if you're behind a proxy you should know and use the correct hostname and port for it. Do you really think myproxy.com is correct?

Another problem could be that it's not a proxy but a firewall which is simply blocking outgoing connections on TCP port 80 (HTTP). Are you trying this at home or in a company or what?

Anyway in principle your application is working!

Marco
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: java.net.ConnectException: Connection refused: connect
 
Similar Threads
Connection timeout with HttpsURLConnection
problem with proxy server
Reading hyperlink in excel through Java
Access to website with proxy using Java Code
java.net.ConnectException: Connection refused: connect