File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .zetcode ;
2
+
3
+ import java .io .IOException ;
4
+ import java .net .URI ;
5
+ import java .net .http .HttpClient ;
6
+ import java .net .http .HttpHeaders ;
7
+ import java .net .http .HttpRequest ;
8
+ import java .net .http .HttpResponse ;
9
+
10
+ public class HeadRequest {
11
+
12
+ public static void main (String [] args ) throws IOException , InterruptedException {
13
+
14
+ HttpClient client = HttpClient .newHttpClient ();
15
+
16
+ var request = HttpRequest .newBuilder (URI .create ("http://webcode.me" ))
17
+ .method ("HEAD" , HttpRequest .BodyPublishers .noBody ())
18
+ .build ();
19
+
20
+ HttpResponse <Void > response = client .send (request ,
21
+ HttpResponse .BodyHandlers .discarding ());
22
+
23
+ HttpHeaders headers = response .headers ();
24
+
25
+ headers .map ().forEach ((key , values ) -> {
26
+ System .out .printf ("%s: %s%n" , key , values );
27
+ });
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments