import java.net.URL;
import java.net.URLConnection;
public class Main {
public static void main(String[] argv) throws Exception {
URL url = new URL("http://hostname:80");
URLConnection conn = url.openConnection();
for (int i = 0;; i++) {
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
System.out.println(headerName);
System.out.println(headerValue);
if (headerName == null && headerValue == null) {
System.out.println("No more headers");
break;
}
}
}
}
|