-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOptions.java
More file actions
33 lines (30 loc) · 1 KB
/
Options.java
File metadata and controls
33 lines (30 loc) · 1 KB
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
import java.io.*;
import java.net.*;
import java.util.*;
public class Options {
public static void main(String[] args) {
try {
URL u = new URL(args[0]);
HttpURLConnection http = (HttpURLConnection) u.openConnection();
http.setRequestMethod("OPTIONS");
Map<String, List<String>> headers = http.getHeaderFields();
for (Map.Entry<String, List<String>> header : headers.entrySet()) {
System.out.println(header.getKey() + ": " + join(header.getValue()));
}
} catch (MalformedURLException ex) {
System.err.println(args[0] + " is not a parseable URL");
} catch (IOException ex) {
System.err.println(ex);
}
System.out.println();
}
private static String join(List<String> list) {
StringBuilder builder = new StringBuilder();
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
builder.append(iterator.next());
if (iterator.hasNext()) builder.append(", ");
}
return builder.toString();
}
}