代理配置

本节主要介绍升级版 SDK 对于代理的配置。

升级版本 SDK 同样也可以通过以下环境变量设置代理:

  • HTTP_PROXY 或者http_proxy

  • HTTPS_PROXY

  • NO_PROXY

或者通过 Config 在初始化 Client 阶段设置请求的代理,升级版 SDK 还支持通过运行时参数(RuntimeOption)配置当前请求的代理。优先级:RuntimeOption > Client > 环境变量:

public static void main(String[] args) {
    Config config = new com.aliyun.teaopenapi.models.Config();
    config.setAccessKeyId("<accessKeyId>");
    config.setAccessKeySecret("<accessSecret>");
    config.setRegionId("<regionId>");
    // Client 代理参数设置
    config.setHttpProxy("http://127.0.0.1:9898");
    config.setHttpsProxy("http://user:password@127.0.0.1:8989");
    config.setNoProxy("127.0.0.1,localhost");
    ecs20140526.Client client = new ecs20140526.Client(config);

    // 运行时参数设置,仅对使用了该运行时参数实例的请求有效
    RuntimeOptions runtimeOptions = new RuntimeOptions();
    runtimeOptions.httpProxy = "http://127.0.0.1:9898";
    runtimeOptions.httpsProxy = "http://user:password@127.0.0.1:8989";
    runtimeOptions.noProxy = "127.0.0.1,localhost";

    DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();

    client.describeRegionsWithOptions(describeRegionsRequest, runtimeOptions);
}

阿里云首页 阿里云SDK 相关技术圈