Home arrow static arrow Java Programming [Archive] - java.net.NoRouteToHostException: No route to host
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - java.net.NoRouteToHostException: No route to host
This topic has 1 reply on 1 page.

Posts:298
Registered: 4/8/04
java.net.NoRouteToHostException: No route to host  
Jun 21, 2004 1:54 PM



 
Hi everybody,
I have the following code. When I run this code with: http://xml.surepay.com
I receive the runtime error (mentioned below) when it tries to:
getResponseCode() or getResponseMessage().

However, if I run it with https://xml.surepay.com, it runs successfulley. (It's a secure apge.)
Why is that? What happens that the error: "java.net.NoRouteToHostException: No route to host" occur?

Any help is greatly appreciated.


Error:

java RedirectingReader1 http://xml.surepay.com
point1
http://xml.surepay.com
point2
java.net.NoRouteToHostException: No route to host


Code:

import java.net.URL;
import java.net.MalformedURLException;
import java.net.HttpURLConnection;
import java.io.IOException;

public class RedirectingReader1
{

private static HttpURLConnection connection;

private static void connect( String urlString ) {
try
{
URL url = new URL(urlString);
connection = (HttpURLConnection)url.openConnection();
System.out.println("point1");
System.out.println(connection.getURL());
System.out.println("point2");
System.out.println(connection.getResponseCode() + " " + connection.getResponseMessage());
System.out.println("point3");
System.out.println(connection.getURL());
System.out.println("point4");
} catch (MalformedURLException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
if (args.length != 1) {
System.err.println(
"usage: java WebPageReader "
+ "<url>");
System.exit(0);
}
connect(args[0]);
}
}
 

Posts:89
Registered: 04-06-04
Re: java.net.NoRouteToHostException: No route to host  
Jun 21, 2004 2:03 PM (reply 1 of 1)



 
A question for a question - did you try both URLs in a browser? If you did then you'll see that it's not just your code that gives an error with the 'http' URL (in other words - the browser also fails in trying to access http://xml.surepay.com ).

These findings indicate that the host server is only accepting secure traffic via https (port 443 by default).

Hope this helps,
brew.man
 
This topic has 1 reply on 1 page.