Skip to content

Commit 4b5a602

Browse files
authored
seed, which keep the commandments of God
And the dragon was wroth with the woman, and went to make war with the remnant of her seed, which keep the commandments of God, and have the testimony of Jesus Christ. (Revelation 12:17)
1 parent 97f9001 commit 4b5a602

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
//And the dragon was wroth with the woman, and went to make war with the remnant of her seed,
3+
//which keep the commandments of God, and have the testimony of Jesus Christ. (Revelation 12:17)
4+
5+
package com.javarush.task.task40.task4006;
6+
7+
import java.io.BufferedReader;
8+
import java.io.IOException;
9+
import java.io.InputStreamReader;
10+
import java.io.PrintStream;
11+
import java.net.HttpURLConnection;
12+
import java.net.Socket;
13+
import java.net.URL;
14+
15+
/*
16+
Отправка GET-запроса через сокет
17+
*/
18+
19+
public class Solution {
20+
public static void main(String[] args) throws Exception {
21+
getSite(new URL("http://javarush.ru/social.html"));
22+
}
23+
24+
public static void getSite(URL url){
25+
String host = url.getHost();
26+
String request = url.getFile();
27+
try (Socket socket = new Socket(host, 80);
28+
PrintStream writer = new PrintStream(socket.getOutputStream());
29+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()))){
30+
writer.print("GET " + /*"/" +*/ request + /*" HTTP/1.1" +*/ "\r\n");
31+
32+
writer.print("\r\n");
33+
writer.flush();
34+
35+
String responseLine;
36+
while ((responseLine = bufferedReader.readLine()) != null) {
37+
System.out.println(responseLine);
38+
}
39+
} catch (IOException e) {
40+
e.printStackTrace();
41+
}
42+
}
43+
}
44+
45+
/*
46+
Отправка GET-запроса через сокет
47+
48+
Перепиши реализацию метода getSite, он должен явно создавать и использовать сокетное соединение Socket с сервером.
49+
50+
Адрес сервера и параметры для GET-запроса получи из параметра url.
51+
52+
Порт используй дефолтный для http (80).
53+
54+
Классы HttpURLConnection, HttpClient и т.д. не использовать.
55+
56+
Не оставляй закомементированный код.
57+
58+
59+
60+
61+
62+
Требования:
63+
64+
1. Метод getSite должен создавать объект класса Socket с правильными параметрами (String host, int port).
65+
66+
2. Метод getSite должен записать в OutputStream правильный запрос.
67+
68+
3. Метод getSite должен выводить на экран InputStream сокета.
69+
70+
4. Метод getSite не должен использовать HttpURLConnection или HttpClient.
71+
*/

0 commit comments

Comments
 (0)