PHP V1.0 için SDK'da ağ proxy'sini istek düzeyinde, istemci düzeyinde veya ortam değişkenleri kullanarak yapılandırabilirsiniz.
Not
Proxy yapılandırması öncelik sırası (yüksekten düşüğe): istek düzeyi ayarları, istemci düzeyi ayarları ve ortam değişkenleri.
-
İstekte proxy yapılandırın.
<?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; } -
İstemcide proxy yapılandırın.
<?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; } -
Ortam değişkenlerini kullanarak proxy yapılandırın.
HTTP_PROXY veya http_proxy
HTTPS_PROXY veya https_proxy
NO_PROXY veya no_proxy