java.net unable to connect to URL

I am trying to connect to a url using java.net to connect to a url but it keeps giving me an UnknownHostException: www.yahoo.com. I have tried everything. The firewall is not blocking java, i am able to ping the website from the computer running the code. I also tested with adding a line for proxy's to allow for the connection but that did not work either. I tried some other websites hosted on my servers as well but with no luck.
import java.net.*;
import java.io.*;

public class URLconnectionReader {
    public static void main(String[] args) throws Exception {
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("77.95.208.230", 8080));
        URL yahoo = new URL("http://www.yahoo.com/");
        URLConnection yc = yahoo.openConnection();
        BufferedReader in = new BufferedReader(
                                new InputStreamReader(
                                yc.getInputStream()));
        String inputLine;

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

Open in new window

abhinav90Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abhinav90Author Commented:
i just tested something. If i change the host to localhost and try and access some http content hosted on my wamp server, then the output was perfect. This is ofcourse after removing the proxy statement on line 6. So i guess the code syntax is fine, there is some other issue.
0
VenabiliCommented:
YOu know that you are not using the Proxy even though you declare it, right?

The code looks ok so I suspect you simply need to configure the proxy. So try to use the Proxy and post back the code with the proxy being used and the error that yiou have after this.

Try to start the program as follows:
java -DproxySet=true -DproxyHost=proxyhost URLconnectionReader

Or alternatovely use:
URL url = new URL("http", "77.95.208.230", 8080, "http://www.yahoo.com/");
(at least I think that worked..)
See http://www.rgagnon.com/javadetails/java-0085.html for the other options.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.