Reputation: 21329
To check if I can connect to the web-app named service I open a connection to its address.How do I check if have connected to this URL/Service ? I was thinking of sending some sort of status method (as a client tries to open connection to this URL) that determines if the client was able to establish a successful connection to the service. But how do I do that ?
I was trying something like this :
final URL url = new URL("http://localhost:8084/service/index.jsp");
final URLConnection urlc = url.openConnection();
InputStream response = urlc.getInputStream();
// Now call a method in the service app that sends a status method...
// .....or can I get away with this ?
Upvotes: 2
Views: 15596
Reputation: 136062
I suggest
URL url = new URL("http://stackoverflow.com/questions/13775103/how-do-i-know-if-i-have-successfully-connected-to-the-url-i-opened-a-connection");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
System.out.println(conn.getResponseCode());
it prints 200
(OK)
Upvotes: 8