-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
42 lines (38 loc) · 1.37 KB
/
Client.java
File metadata and controls
42 lines (38 loc) · 1.37 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
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;
public class Client {
public static void main(String args[]) throws IOException {
Socket socket = new Socket("127.0.0.1", 8080);
Scanner userInput = new Scanner(System.in), socketInput = new Scanner(socket.getInputStream());
PrintStream socketOutput = new PrintStream(socket.getOutputStream());
String message;
System.out.print("Enter HTTP Request Header: ");
message = userInput.nextLine();
String line;
String RequestBody = "";
if (message.contains("GET"))
{
socketOutput.print(message + "\r\n\r\n");
}
if (message.contains("POST")) {
while (true) {
line = userInput.nextLine();
if (line.equals("FINISHED"))
break;
RequestBody += line;
RequestBody += "\r\n";
}
RequestBody += "\r\n\r\n";
socketOutput.print(message + "\r\n\r\n");
socketOutput.print(RequestBody);
}
else if (message.contains("DELETE"))
{
socketOutput.print(message + "\r\n\r\n");
}
while(socketInput.hasNextLine())
System.out.println(socketInput.nextLine());
}
}