• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.net.ConnectException: Connection refused: connect

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
}
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic