以下是一个简单的示例,展示如何使用 Java 调用全速数据提供的足球 API:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class FootballAPICall {
public static void main(String[] args) {
try {
// 设置API密钥
String apiKey = "YOUR_API_KEY";
// 目标API端点URL
String apiUrl = "https://.../api/football";
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("X-RapidAPI-Key", apiKey);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// 输出API响应
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
在这个示例中,你需要将 `YOUR_API_KEY` 替换为你在全速数据提供的实际 API 密钥。这个示例发送一个 GET 请求来获取足球数据,你可以根据实际需求调整 API 端点 URL 和请求参数。请根据你的实际需求处理 API 响应数据。