最近更新时间:2026-06-03 21:32:12
以下代码用于设置访问者公网访问配置:
public void putPublicNetworkBlock() {
// 初始化 Ks3Client, 参见"初始化"文档
Ks3Client ks3Client = initKs3Client();
try {
// 创建公网访问控制配置
PublicNetworkBlockConfiguration config = new PublicNetworkBlockConfiguration();
// 设置阻止公网访问类型
// All: 阻止所有公网访问
// ExcludeAuthorization: 阻止公网访问,有效鉴权除外
// ExcludeConsole: 阻止公网访问,控制台访问除外
config.setBlockType(PublicNetworkBlockType.All);
// 或者使用字符串方式设置
// config.setBlockType("All");
// 设置公网访问控制规则
ks3Client.putPublicNetworkBlock(new PutPublicNetworkBlockRequest(config));
System.out.println("公网访问控制规则设置成功");
} catch (Ks3ServiceException e) {
System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
System.out.println("Error Message: " + e.getErrorMessage());
System.out.println("Error Code: " + e.getErrorCode());
System.out.println("Request ID: " + e.getRequestId());
} catch (Ks3ClientException e) {
System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
System.out.println("Error Message: " + e.getMessage());
} finally {
// 不再使用时,关闭 Ks3Client
ks3Client.shutdown();
}
}
以下代码用于获取访问者公网访问配置:
public void getPublicNetworkBlock() {
// 初始化 Ks3Client, 参见"初始化"文档
Ks3Client ks3Client = initKs3Client();
try {
PublicNetworkBlockConfiguration config = ks3Client.getPublicNetworkBlock();
System.out.println("当前公网访问控制类型: " + config.getBlockType());
// 根据类型输出中文说明
String blockTypeDesc = "";
switch (config.getBlockType()) {
case "All":
blockTypeDesc = "阻止所有公网访问";
break;
case "ExcludeAuthorization":
blockTypeDesc = "阻止公网访问,有效鉴权除外";
break;
case "ExcludeConsole":
blockTypeDesc = "阻止公网访问,控制台访问除外";
break;
default:
blockTypeDesc = "未知类型";
}
System.out.println("说明: " + blockTypeDesc);
} catch (Ks3ServiceException e) {
System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
System.out.println("Error Message: " + e.getErrorMessage());
System.out.println("Error Code: " + e.getErrorCode());
System.out.println("Request ID: " + e.getRequestId());
} catch (Ks3ClientException e) {
System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
System.out.println("Error Message: " + e.getMessage());
} finally {
// 不再使用时,关闭 Ks3Client
ks3Client.shutdown();
}
}
以下代码用于删除访问者公网访问配置:
public void deletePublicNetworkBlock() {
// 初始化 Ks3Client, 参见"初始化"文档
Ks3Client ks3Client = initKs3Client();
try {
ks3Client.deletePublicNetworkBlock();
System.out.println("公网访问控制规则删除成功");
} catch (Ks3ServiceException e) {
System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
System.out.println("Error Message: " + e.getErrorMessage());
System.out.println("Error Code: " + e.getErrorCode());
System.out.println("Request ID: " + e.getRequestId());
} catch (Ks3ClientException e) {
System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
System.out.println("Error Message: " + e.getMessage());
} finally {
// 不再使用时,关闭 Ks3Client
ks3Client.shutdown();
}
}
纯净模式
