文档

代理配置

更新时间:
一键部署

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

升级版 SDK 同样可以通过环境变量:
• HTTP_PROXY 或者 http_proxy
• HTTPS_PROXY
• NO_PROXY
或者通过 Config 在初始化 Client 阶段设置请求的代理,升级版 SDK 还支持通过运行时参数(RuntimeOption)配置当前请求的代理。优先级: RuntimeOption > Client > 环境变量,以ECS DescribeInstances接口为例:
use AlibabaCloud\SDK\Ecs\V20140526\Ecs;
use AlibabaCloud\Tea\Tea;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Console\Console;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Ecs\V20140526\Models\DescribeInstancesRequest;
public static function main($args){
        // Client 代理参数设置
        $config = new Config([
            "accessKeyId" => "<accessKeyId>"
            "accessKeySecret" => "<accessSecret>",
            "endpoint" => "<endpoint>"
            // Client 代理参数设置
            "httpProxy" => "http://localhost:8125",
            "httpsProxy" => "https://localhost:9124",
            "noProxy" => "http://localhost:9527"
        ]);
        $client = new Ecs($config);

        // 运行时参数设置,仅对使用了该运行时参数实例的请求有效
        $runtime = new RuntimeOptions([
            "httpProxy" => "http://localhost:8080",
            "httpsProxy" => "https://localhost:9527"
            "noProxy" => "http://localhost:1024"
        ]);
        $describeInstancesRequest = new DescribeInstancesRequest([
            "regionId" => "cn-shanghai"
        ]);
        $resp = $client->describeInstancesWithOptions($describeInstancesRequest,$runtime);
}
  • 本页导读 (1)