-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArbitaryFields.java
31 lines (28 loc) · 1.06 KB
/
ArbitaryFields.java
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
// 15. Write a program for retrieving Arbitrary Fields.
import java.io.*;
import java.net.*;
public class ArbitaryFields {
public static void main(String[] args) {
// Define the URL you want to test
String[] urls = {"https://www.lict.edu.np"};
for (String urlString : urls) {
try {
// Create a URL object from the string
URL u = new URL(urlString);
// Open a connection to the URL
URLConnection uc = u.openConnection();
// Print all the headers
for (int j = 1;; j++) {
String header = uc.getHeaderField(j);
if (header == null) break;
System.out.println(uc.getHeaderFieldKey(j) + ": " + header);
}
} catch (MalformedURLException ex) {
System.err.println(urlString + " is not a URL I understand.");
} catch (IOException ex) {
System.err.println(ex);
}
System.out.println();
}
}
}