This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic Connection refused: connect  RSS feed

Ketan Parekh
Posts: 20
  • Mark post as helpful
  • send pies
  • 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: 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.*;

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


URL yahoo = new URL("");
URLConnection yc = yahoo.openConnection();

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

String inputLine;

while ((inputLine = in.readLine()) != null)

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

Properties newprops = new Properties(props);

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



Thanks in Advance.

Isuru Sampath
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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.



  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!