forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPS.java
More file actions
55 lines (50 loc) · 1.19 KB
/
Copy pathHTTPS.java
File metadata and controls
55 lines (50 loc) · 1.19 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
package javaforce;
/** HTTPS Client.
*
* @author pquiring
*/
public class HTTPS extends HTTP {
static {
JF.initHttps();
}
public boolean open(String host) {
return open(host, 443);
}
public boolean open(String host, int port) {
this.host = host;
this.port = port;
try {
s = JF.connectSSL(host, port);
os = s.getOutputStream();
is = s.getInputStream();
} catch (Exception e) {
JFLog.log(e);
return false;
}
return true;
}
/** Test HTTPS */
public static void main(String[] args) {
HTTPS http = new HTTPS();
String html;
boolean print = false;
if (args.length > 0 && args[0].equals("print")) print = true;
HTTP.debug = true;
http.open("google.com");
html = http.getString("/");
http.close();
if (html == null || html.length() == 0) {
System.out.println("Error:HTTPS.get() failed");
return;
}
if (print) System.out.println(html);
http.open("www.google.com");
html = http.getString("/");
http.close();
if (html == null || html.length() == 0) {
System.out.println("Error:HTTPS.get() failed");
return;
}
if (print) System.out.println(html);
}
}