small Java HTTP client
package httpclient;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class HttpClient {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage: httpclient <url>");
return;
}
try {
URL url = new URL(args[0]);
URLConnection client = url.openConnection();
InputStream inputStream = client.getInputStream();
byte[] buf = new byte[1024];
for (int len; (len = inputStream.read(buf)) > 0;) {
System.out.write(buf, 0, len);
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}