0

I am trying to call URL from java but am getting error as java.net.UnknownHostException:

Java Code:

    URL url = new URL("http://www.gettingagile.com/feed/rss2/");
    HttpURLConnection request = (HttpURLConnection) url.openConnection();
    String code = String.valueOf(request.getResponseCode());
    System.out.println("Error code "+code);
yusuf
  • 73
  • 1
  • 9
  • 2
    Your code works for me. – wonderb0lt Jun 05 '15 at 11:20
  • am getting java.net.UnknownHostException: www.gettingagile.com – yusuf Jun 05 '15 at 11:22
  • 3
    Maybe you're behind a firewall that is blocking access, or maybe your dev machine isn't even properly connected to the internet. your code seems fine – Timothy Groote Jun 05 '15 at 11:23
  • It also works for me. Look if you have another application that it's blocking your network connection. – Francisco Romero Jun 05 '15 at 11:27
  • May be your machine has proxy configurations, but your code doesn't identify any gateways... try using this method: http://stackoverflow.com/questions/1432961/how-do-i-make-httpurlconnection-use-a-proxy or http://stackoverflow.com/questions/15927079/how-to-use-httpsurlconnection-through-proxy-by-setproperty – Chand Priyankara Jun 05 '15 at 11:42

1 Answers1

1

An UnknownHostException generally means that java couldn't resolve the host, in this case www.gettingagile.com.

Maybe your firewall is blocking access for java, maybe your computer is not connected to the internet or there might be a problem with your DNS server.

Can you surf to www.gettingagile.com in your browser? And can you ping the address from a shell or commandline?

Buurman
  • 1,914
  • 17
  • 26