How to check if given URL is valid with FtpURLConnection?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Sunday, September 1, 2002 10:54 PM

Hi, I have to implement little code that validates http and ftp URLs. I have managed to do the trick with HttpURLConnection for http. I've made it like this: HttpURLConnection connection = (HttpURLConnection)urli.openConnection(); System.out.println(connection.getResponseCode()); But how can I make the same trick for ftp? I made some testing and got one solution: FtpURLConnection connection = (FtpURLConnection)urli.openConnection(); connection.connect(); System.out.println(connection.getContentType()); That code tries to connect to given URL. Then it tries to get the content-type. I noticed that the returned content type is "content/unknown" if th   More>>

Hi, I have to implement little code that validates http and ftp URLs. I have managed to do the trick with HttpURLConnection for http. I've made it like this:



			
HttpURLConnection connection = (HttpURLConnection)urli.openConnection();
System.out.println(connection.getResponseCode());


But how can I make the same trick for ftp?


I made some testing and got one solution:



			
FtpURLConnection connection = (FtpURLConnection)urli.openConnection();
connection.connect();
System.out.println(connection.getContentType());


That code tries to connect to given URL. Then it tries to get the content-type. I noticed that the returned content type is "content/unknown" if the URL is not valid.


Now I would like to know if there is "correct" way to do that? Or can I trust that piece of code?

   <<Less
About | Sitemap | Contact