File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments