import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class ApiCaller {
public static void main(String[] args) {
try {
String apiUrl = "https://cdsp.ppsu.edu.cn/cdsp/data-api/v2/DS0001";
String appId = "yourAppId";
String timestamp = "yourTimestamp";
String signature = "yourSignature";
String fullUrl = apiUrl + "?appId=" + appId + "×tamp=" + timestamp + "&signature=" + signature;
URL url = new URL(fullUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine())!= null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} else {
System.out.println("请求失败,错误码: " + responseCode);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}