No SDK for PHP V1.0, configure um proxy de rede no nível da requisição, no nível do cliente ou por meio de variáveis de ambiente.
Nota
Prioridade da configuração de proxy em ordem decrescente: configurações no nível da requisição, configurações no nível do cliente e variáveis de ambiente.
-
configure um proxy na requisição.
<?php require_once 'vendor/autoload.php'; use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; use AlibabaCloud\Ecs\Ecs; try { // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured. AlibabaCloud::accessKeyClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET')); $request = Ecs::v20140526()->describeRegions(); $result = $request ->version('2014-05-26') ->product('Ecs') ->action('DescribeRegions') ->regionId('cn-hangzhou') ->host("ecs.cn-hangzhou.aliyuncs.com") ->scheme("http") // If you set the proxy parameter to https, set the scheme parameter to https. If you set the proxy parameter to http or no, set the scheme to http. Otherwise, the proxy does not take effect. ->options([ 'proxy' => [ 'http' => 'http://localhost:8080', // Use this proxy with "http" // 'https' => 'http://localhost:9124', // Use this proxy with "https", // 'no' => ['example.com'] // Don't use a proxy with these ] ]) ->request(); print_r($result->toArray()); } catch (ClientException $exception) { // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, the information is displayed for reference only. echo $exception->getMessage() . PHP_EOL; } catch (ServerException $exception) { // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, the information is displayed for reference only. echo $exception->getMessage() . PHP_EOL; echo $exception->getErrorCode() . PHP_EOL; echo $exception->getRequestId() . PHP_EOL; echo $exception->getErrorMessage() . PHP_EOL; } -
configure um proxy no cliente.
<?php require_once 'vendor/autoload.php'; use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; use AlibabaCloud\Ecs\Ecs; try { // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured. AlibabaCloud::accessKeyClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET')) ->asDefaultClient() ->options([ 'proxy' => [ 'http' => 'http://localhost:8080', // Use this proxy with "http" // 'https' => 'http://localhost:9124', // Use this proxy with "https", // 'no' => ['localhost'] // Don't use a proxy with these ] ]); $request = Ecs::v20140526()->describeRegions(); $result = $request ->version('2014-05-26') ->product('Ecs') ->action('DescribeRegions') ->regionId('cn-hangzhou') ->host("ecs.cn-hangzhou.aliyuncs.com") ->scheme("http") // If you set the proxy parameter to https, set the scheme parameter to https. If you set the proxy parameter to http or no, set the scheme to http. Otherwise, the proxy does not take effect. ->request(); print_r($result->toArray()); } catch (ClientException $exception) { // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, the information is displayed for reference only. echo $exception->getMessage() . PHP_EOL; } catch (ServerException $exception) { // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, the information is displayed for reference only. echo $exception->getMessage() . PHP_EOL; echo $exception->getErrorCode() . PHP_EOL; echo $exception->getRequestId() . PHP_EOL; echo $exception->getErrorMessage() . PHP_EOL; } -
configure um proxy com variáveis de ambiente.
HTTP_PROXY ou http_proxy
HTTPS_PROXY ou https_proxy
NO_PROXY ou no_proxy