-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
50 lines (33 loc) · 1.09 KB
/
test.java
File metadata and controls
50 lines (33 loc) · 1.09 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package lab2;
import java.net.*;
import java.util.Scanner;
import java.io.*;
public class test {
public static void main(String[] args) throws Exception {
Socket connectionSocket = new Socket("10.2.11.136", 80);
System.out.println("Connection is established!");
System.out.println("Please enter the URL address of the web page. ");
Scanner scanner = new Scanner(System.in);
String urls = "http://" + scanner.nextLine() + "/";
URL url = new URL(urls);
String host = url.getHost();
String path = url.getPath();
BufferedReader bf = new BufferedReader(
new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream dos = new DataOutputStream(connectionSocket.getOutputStream());
dos.writeBytes("GET " + path+" HTTP/1.0\r\n"
+ "Host: "+host
+ "\r\n\r\n");
String loop = "";
while(true) {
String anotherString = bf.readLine();
if(anotherString == null) {
connectionSocket.close();
break;
}
loop += anotherString + "\n";
}
System.out.println(loop);
}
}
//http://10.2.11.136/path/anotherPath/