Skip to content

Commit 26858a3

Browse files
committed
add HttpsCaller
1 parent 3626e15 commit 26858a3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/HttpsCaller.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.net.*;
2+
import java.io.*;
3+
import javax.net.ssl.HttpsURLConnection;
4+
5+
public class HttpsCaller {
6+
public static String callHttps() {
7+
try {
8+
URL url = new URL("https://api.github.com/");
9+
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
10+
conn.setRequestMethod("GET");
11+
12+
BufferedReader in = new BufferedReader(
13+
new InputStreamReader(conn.getInputStream()));
14+
String inputLine;
15+
StringBuilder content = new StringBuilder();
16+
17+
while ((inputLine = in.readLine()) != null) {
18+
content.append(inputLine);
19+
}
20+
in.close();
21+
conn.disconnect();
22+
return content.toString();
23+
} catch (Exception e) {
24+
return "Error: " + e.getMessage();
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)