質問編集履歴
1
コードに追加点が発生した為、変更しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,11 +20,21 @@
|
|
20
20
|
|
21
21
|
import java.awt.Font;
|
22
22
|
|
23
|
+
import java.io.ByteArrayOutputStream;
|
24
|
+
|
23
25
|
import java.io.IOException;
|
26
|
+
|
27
|
+
import java.net.HttpURLConnection;
|
24
28
|
|
25
29
|
import java.net.URL;
|
26
30
|
|
27
31
|
import java.net.URLConnection;
|
32
|
+
|
33
|
+
import java.nio.charset.StandardCharsets;
|
34
|
+
|
35
|
+
import java.util.List;
|
36
|
+
|
37
|
+
import java.util.Map.Entry;
|
28
38
|
|
29
39
|
|
30
40
|
|
@@ -80,13 +90,51 @@
|
|
80
90
|
|
81
91
|
try {
|
82
92
|
|
83
|
-
URL url = new URL("http://www.
|
93
|
+
URL url = new URL("http://www.google.co.jp/");
|
84
94
|
|
85
95
|
URLConnection connect = url.openConnection();
|
86
96
|
|
87
97
|
connect.getInputStream();
|
88
98
|
|
89
99
|
internet = true;
|
100
|
+
|
101
|
+
HttpURLConnection connect1 = (HttpURLConnection) url.openConnection();
|
102
|
+
|
103
|
+
System.out.println(connect1.getResponseCode());
|
104
|
+
|
105
|
+
System.out.println(connect1.getResponseMessage());
|
106
|
+
|
107
|
+
System.out.println(connect1.getContentType());
|
108
|
+
|
109
|
+
for(Entry<String, List<String>> header: connect1.getHeaderFields().entrySet()) {
|
110
|
+
|
111
|
+
for(String value: header.getValue()) {
|
112
|
+
|
113
|
+
System.out.println(header.getKey() + ":" + value);
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
try(java.io.InputStream in = connect1.getInputStream();
|
120
|
+
|
121
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream()){
|
122
|
+
|
123
|
+
byte[] buf = new byte[1024 * 8];
|
124
|
+
|
125
|
+
int length = 0;
|
126
|
+
|
127
|
+
int lenght;
|
128
|
+
|
129
|
+
while((lenght = in.read(buf)) != -1) {
|
130
|
+
|
131
|
+
out.write(buf,0,lenght);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
System.out.println(new String(out.toByteArray(), StandardCharsets.UTF_8));
|
136
|
+
|
137
|
+
}
|
90
138
|
|
91
139
|
} catch(IOException ex) {
|
92
140
|
|
@@ -95,8 +143,6 @@
|
|
95
143
|
}
|
96
144
|
|
97
145
|
System.out.println("接続:" + internet);
|
98
|
-
|
99
|
-
|
100
146
|
|
101
147
|
});
|
102
148
|
|
@@ -112,9 +158,11 @@
|
|
112
158
|
|
113
159
|
getContentPane().add(panel,BorderLayout.CENTER);
|
114
160
|
|
161
|
+
}
|
115
162
|
|
116
163
|
|
117
|
-
|
164
|
+
|
165
|
+
|
118
166
|
|
119
167
|
public static void main(String args[]) {
|
120
168
|
|
@@ -123,6 +171,10 @@
|
|
123
171
|
Search frame = new Search();
|
124
172
|
|
125
173
|
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
}
|
126
178
|
|
127
179
|
```
|
128
180
|
|