文档

删除白名单Java SDK调用示例

更新时间:

本文介绍了删除白名单的Java SDK调用示例。

前提条件

  • 已注册阿里云账号并获取AccessKey ID和AccessKey Secret。更多信息,请参见创建AccessKey

  • 需要使用的Java版本在1.8版本及以上。

使用Maven引入SDK

<dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>cloudauth20190307</artifactId>
            <version>1.0.2</version>
</dependency>

示例

import com.aliyun.cloudauth20190307.Client;
import com.aliyun.cloudauth20190307.models.DeleteWhitelistRequest;
import com.aliyun.cloudauth20190307.models.DeleteWhitelistResponse;
import com.aliyun.tearpc.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

public class DeleteWhitelist {

    public static void main(String[] args){

        // 通过以下代码创建API请求并设置参数。
        DeleteWhitelistRequest request = new DeleteWhitelistRequest();
        // 要删除的白名单规则的ID。该参数值通过调用DescribeWhitelist获取。
        request.setIds("563,484");

        try {
            DeleteWhitelistResponse response = deleteWhitelist(request);
            if (response != null) {
                System.out.println(response.getRequestId());

            }
        } catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

    private static DeleteWhitelistResponse deleteWhitelist(DeleteWhitelistRequest request)
        throws Exception {
        // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
        // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
        // 本示例通过阿里云Credentials工具从环境变量中读取AccessKey,来实现API访问的身份验证。如何配置环境变量,请参见https://help.aliyun.com/document_detail/378657.html。
        com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
        Config config = new Config();
        config.setCredential(credentialClient);
        config.setEndpoint("cloudauth.aliyuncs.com");
        // 设置http代理。
        //config.setHttpProxy("<http://xxx.x.x.x:xxxx>");
        // 设置https代理。
        //config.setHttpsProxy("<http://xxx.x.x.x:xxxx>");
        Client client = new Client(config);

        // 创建RuntimeObject实例并设置运行参数。
        RuntimeOptions runtime = new RuntimeOptions();
        // 设置连接超时时间(单位ms),您可以根据实际情况设置。
        runtime.readTimeout = 10000;
        // 设置调用超时时间(单位ms),您可以根据实际情况设置。
        runtime.connectTimeout = 10000;

        return client.deleteWhitelist(request, runtime);
    }
}
  • 本页导读
文档反馈