forked from cstrahan/aduni
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownload.java
More file actions
38 lines (32 loc) · 891 Bytes
/
Download.java
File metadata and controls
38 lines (32 loc) · 891 Bytes
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
import java.io.*;
import java.net.*;
class Download{
public static void main(String[] args){
Socket s = null;
PrintWriter fout;
BufferedReader fin;
try{
s = new Socket(args[0],80);
System.out.println("connected");
fout = new PrintWriter(
new OutputStreamWriter(s.getOutputStream()));
fin = new BufferedReader(
new InputStreamReader(s.getInputStream()));
String path = "GET " + args[1] + " HTTP/1.0\n\n";
// send GET
fout.print(path);
// Must flush or command never gets sent!!
fout.flush();
//read response
String line;
System.out.println("sent request");
while((line = fin.readLine()) != null){
System.out.println(line);
}
s.close();
}
catch(IOException e){
System.out.println("Cannot connect");
}
}
}