-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathUseSSL.java
More file actions
31 lines (30 loc) · 781 Bytes
/
UseSSL.java
File metadata and controls
31 lines (30 loc) · 781 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
public static void main(String[] args) {
{
try {
URL u = new URL("http://www.secret.example.org/");
HttpURLConnection httpcon = (HttpURLConnection) u.openConnection();
httpcon.setRequestMethod("PUT");
httpcon.connect();
// BAD: output stream from non-HTTPS connection
OutputStream os = httpcon.getOutputStream();
httpcon.disconnect();
}
catch (IOException e) {
// fail
}
}
{
try {
URL u = new URL("https://www.secret.example.org/");
HttpsURLConnection httpscon = (HttpsURLConnection) u.openConnection();
httpscon.setRequestMethod("PUT");
httpscon.connect();
// GOOD: output stream from HTTPS connection
OutputStream os = httpscon.getOutputStream();
httpscon.disconnect();
}
catch (IOException e) {
// fail
}
}
}