Skip to content

Commit 6167ae6

Browse files
committed
add GetTags.java
1 parent 0757918 commit 6167ae6

File tree

1 file changed

+48
-0
lines changed
  • src/main/java/top/mryan2005/simplifiedjava/flarum

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package top.mryan2005.simplifiedjava.flarum;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.net.HttpURLConnection;
7+
import java.net.URL;
8+
9+
public class GetTags {
10+
private String hostUrl;
11+
12+
public GetTags(String hostUrl) {
13+
this.hostUrl = hostUrl;
14+
}
15+
16+
public StringBuffer getTags() throws IOException {
17+
18+
// URL of the server endpoint
19+
URL url = new URL(this.hostUrl);
20+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
21+
22+
// Set the request method to GET
23+
connection.setRequestMethod("GET");
24+
25+
// Set request headers
26+
connection.setRequestProperty("Accept", "application/json");
27+
28+
// Get the response code
29+
int responseCode = connection.getResponseCode();
30+
System.out.println("Response Code: " + responseCode);
31+
32+
// Read the response
33+
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
34+
String inputLine;
35+
StringBuffer response = new StringBuffer();
36+
while ((inputLine = in.readLine()) != null) {
37+
response.append(inputLine);
38+
}
39+
in.close();
40+
41+
return response;
42+
}
43+
44+
public static void main(String[] args) throws IOException {
45+
GetTags GetTags1 = new GetTags("https://xxxx.com/api/tags?include=parent");
46+
System.out.println(GetTags1.getTags());
47+
}
48+
}

0 commit comments

Comments
 (0)