All Products
Search
Document Center

Alibaba Cloud SDK:Configure an HTTPS request

Last Updated:Sep 15, 2023

This topic describes how to configure an HTTPS request in Alibaba Cloud Classic SDK.

Configure an HTTPS request

You can configure an SDK client to send API requests over HTTPS.

AlibabaCloud::xxx()
               ->scheme('https') // Specify the protocol over which API requests are sent. The default protocol is HTTP.

Disable certificate verification

You can configure an SDK client to disable certificate verification. You can configure other HTTP settings in Guzzle. For more information, see Request Options.

Important

By default, if you send an API request over HTTPS, the SDK enables certificate verification to verify the validity of SSL/TLS certificates. If no SSL/TLS certificate is configured in the development environment, an error that indicates the certificate verification fails is reported.

To ensure network communication security, we recommend that you enable certificate verification. If certificate verification must be disabled in the test environment, you can set the verify parameter to false.

// Disable certificate verification for an HTTPS-enabled client.
AlibabaCloud::xxx()
              ->regionId('cn-hangzhou')
              ->verify(false)
              ->asDefaultClient();

Specify a custom certificate

  1. Specify a certificate for an API request:

<?php

use AlibabaCloud\Client\AlibabaCloud;

$request = AlibabaCloud::rpc()
                       ->product('Sts')
                       ->version('2015-04-01')
                       ->action('GenerateSessionAccessKey')
                       ->host('sts.ap-northeast-1.aliyuncs.com');

// Query a certificate in the operating system.
$request->verify(true);

// Use the specific certificate.
$request->verify(['verify' => '/path/to/cert.pem']);

// Use the specific certificate and password.
$request->verify(['verify' => ['/path/to/cert.pem','password']]);

2. Specify a certificate for the client:

<?php

use AlibabaCloud\Client\AlibabaCloud;

// Query a certificate in the operating system.
AlibabaCloud::getDefaultClient()
            ->verify(true)
            ->asDefaultClient();

// Use the specific certificate.
AlibabaCloud::getDefaultClient()
            ->verify(['verify' => '/path/to/cert.pem'])
            ->asDefaultClient();

// Use the specific certificate and password.
AlibabaCloud::getDefaultClient()
            ->verify(['/path/to/cert.pem','password'])
            ->asDefaultClient();