1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public class Test {
public static void main(String s[]) {
String u = (s.length == 0) ? "http://www.yahoo.com" : s[0];
Test.dump(u);
System.out.println("**************");
}
public static void dump(String URLName) {
try {
DataInputStream di = null;
FileOutputStream fo = null;
byte[] b = new byte[1];
// PROXY Authenticator
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("PROXY_USER", "PROXY_PASSWORD".toCharArray());
}
});
URL u = new URL(URLName);
HttpURLConnection con = (HttpURLConnection) u.openConnection();
//
// it's not the greatest idea to use a sun.misc.* class
// Sun strongly advises not to use them since they can
// change or go away in a future release so beware.
//
di = new DataInputStream(con.getInputStream());
while (-1 != di.read(b, 0, 1)) {
System.out.print(new String(b));
}
} catch (Exception e) {
e.printStackTrace();
}
}
} |
Partager