File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import java .io .InputStreamReader ;
66import java .io .PrintWriter ;
77import java .net .Socket ;
8- import java .net .UnknownHostException ;
98
109public class SocketHeadRequest {
1110
12- public static void main (String [] args ) {
11+ public static void main (String [] args ) throws IOException {
1312
1413 var hostname = "webcode.me" ;
1514 int port = 80 ;
@@ -26,21 +25,17 @@ public static void main(String[] args) {
2625 writer .println ("Connection: close" );
2726 writer .println ();
2827
29- try (var reader = new BufferedReader (new InputStreamReader (socket .getInputStream ()))) {
28+ try (var reader = new BufferedReader (new InputStreamReader (
29+ socket .getInputStream ()))) {
30+
3031 String line ;
3132
3233 while ((line = reader .readLine ()) != null ) {
34+
3335 System .out .println (line );
3436 }
3537 }
3638 }
37- } catch (UnknownHostException ex ) {
38-
39- System .out .println ("Server not found: " + ex .getMessage ());
40-
41- } catch (IOException ex ) {
42-
43- System .out .println ("I/O error: " + ex .getMessage ());
4439 }
4540 }
4641}
You can’t perform that action at this time.
0 commit comments