and then have the program "read" from the command prompt. sorry if this is kinda vague, but im not exactly sure how to explain it. if you need a better explaination i can try again =P
03-08-2006, 07:35 PM
arul
HttpURLConnection
If I have understood you correctly,
you need to write a simple Java class (say MyURLPing.java) which takes the URL name as the argument from the command line and does a ping using the java library class HttpURLConnection.java .
you run your class as follows:
Code:
C:/> java MyURLPing "www.google.com"
your main class will look something like
Code:
public class MyURLPing {
public static void main(String[] args) {
String url = args[0]; //eg www.google.com
try {
URL u = new URL(url);//
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setRequestMethod("PUT");
huc.connect();
OutputStream os = huc.getOutputStream();
int code = huc.getResponseCode();
if (code >= 200 ) {
// put the data...
}
huc.disconnect();
}
catch (IOException e) { //...
}
}
hope this helps.
03-08-2006, 08:29 PM
anubis
ah, ok thats easier then what i was trying to do lol. thanks