unable to connect to URL

I am trying to connect to a url using to connect to a url but it keeps giving me an UnknownHostException: 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.

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

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

Open in new window

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.
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", "", 8080, "");
(at least I think that worked..)
See for the other options.

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

From novice to tech pro — start learning today.