-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathHeadRequest.java
More file actions
29 lines (21 loc) · 847 Bytes
/
HeadRequest.java
File metadata and controls
29 lines (21 loc) · 847 Bytes
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
package com.zetcode;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class HeadRequest {
public static void main(String[] args) throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder(URI.create("http://webcode.me"))
.method("HEAD", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<Void> response = client.send(request,
HttpResponse.BodyHandlers.discarding());
HttpHeaders headers = response.headers();
headers.map().forEach((key, values) -> {
System.out.printf("%s: %s%n", key, values);
});
}
}