forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebDataLesson.java
More file actions
58 lines (49 loc) · 2.13 KB
/
WebDataLesson.java
File metadata and controls
58 lines (49 loc) · 2.13 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
51
52
53
54
55
56
57
58
package network;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class WebDataLesson {
public static void main(String[] args) throws IOException {
URLConnection connection = new URL("http://www.google.com/").openConnection();
Scanner scanner = new Scanner(connection.getInputStream());
scanner.useDelimiter("\\Z");
System.out.println(scanner.next());
Map<String,List<String>> headerFields = connection.getHeaderFields();
for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) {
System.out.println(entry.getKey() + "/" + entry.getValue());
}
// connection.setDoOutput(true);
// try(PrintWriter out = new PrintWriter(connection.getOutputStream())) {
// out.print("q" + "=" + URLEncoder.encode("test", "UTF-8"));
// }
// for (int i = 0; i < 100; i++) {
// String value = connection.getHeaderField(i);
// if(value == null) {
// break;
// } else {
// System.out.println(value);
// }
// }
// Map<String,List<String>> headerFields = connection.getHeaderFields();
// for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) {
// System.out.println(entry.getKey() + "/" + entry.getValue());
// }
// URLConnection connection = url.openConnection();
// connection.setDoOutput(true);
// connection.connect();
// System.out.println(connection.getContentEncoding());
// System.out.println(connection.getContentLength());
// System.out.println(connection.getContentType());
// System.out.println(connection.getContent());
// System.out.println(connection.getDate());
// System.out.println(connection.getExpiration());
// System.out.println(connection.getLastModified());
// Scanner scanner = new Scanner(connection.getInputStream());
// if(scanner.hasNextLine()) {
// System.out.println(scanner.nextLine());
// }
}
}