SAP公司的Employee Self-Service API REST是一种用于员工自助服务的应用程序接口。它使用户能够访问与其个人信息相关的数据,如薪资单、工作计划和休假时间等。该API使用RESTful架构风格,以实现可扩展性、灵活性和性能。以下是使用Java编写SAP - Employee Self-Service API REST的代码示例:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class EmployeeSelfServiceAPI {
public static void main(String[] args) throws Exception {
String API_URL = "http://sap-employee-self-service-api.com/employees/1";
String ACCESS_TOKEN = "your_access_token_here";
URL url = new URL(API_URL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", "Bearer " + ACCESS_TOKEN);
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) { // success
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} else {
System.out.println("GET request failed.");
}
}
}