• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

java.net.ConnectException: Connection refused: connect

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i have a written a simple program to connect to yahoo and read the content of the webpage.

It is giving me Exception: java.net.ConnectException: Connection refused:

i have also set the proxy settings in the program. I am able to connect to my company website but it is not connection to yahoo or google or msn etc.

can u suggest some solution to this problem.

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

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


try{

URL yahoo = new URL("http://www.yahoo.com");
URLConnection yc = yahoo.openConnection();
yc.setConnectTimeout(7000);
yc.connect();

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

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();



Properties props= new Properties(System.getProperties());
props.put("http.proxySet", "true");
props.put("http.proxyHost", "192.168.151.25");
props.put("http.proxyPort", "80");

Properties newprops = new Properties(props);
System.setProperties(newprops);

} catch (MalformedURLException me) {
System.out.println("MalformedURLException: " + me);
me.printStackTrace();
} catch (IOException ioe) {
//System.out.println("IOException:1" + ioe);
ioe.printStackTrace();

}



}
}


Thanks in Advance.

Regards,
Ketan.B.Parekh
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Parekh,

Since I�m also spending a lot of my time behind a proxy I got the chance to try your problem out.

When I first tried I got an HTTP 407 Error which describes �Proxy Authentication required�.

Proxy authentication is not so much different form a basic http request. All you have to do is set the �Proxy-Authorization� parameter for the proxy.

Please note that I was behind an HTTP proxy and this example may not work if you are behind a SOCKS proxy.

Cheers,

Sampath

 
reply
    Bookmark Topic Watch Topic
  • New Topic