All Products
Search
Document Center

Alibaba Cloud SDK:Configure an HTTPS request

Last Updated:Sep 06, 2023

Alibaba Cloud Darabonba SDK allows you to specify the protocol over which API requests are sent. We recommend that you send API requests over HTTPS. If you do not specify the protocol, API requests are sent over HTTPS by default.

public static void Main(string[] args)
{
    AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config();
    // Specify HTTPS as the protocol when you initialize the client.
    config.Protocol = "HTTPS";
    config.Endpoint = "ecs.cn-beijing.aliyuncs.com";
    AlibabaCloud.SDK.Ecs20140526.Client client = new AlibabaCloud.SDK.Ecs20140526.Client(config);

    DescribeInstancesRequest request = new DescribeInstancesRequest();
    // Process the HTTPS request to serialize the returned results into a response object in the SDK based on the core library.
    var response = client.DescribeInstances(request);
    System.Console.WriteLine(response.Body.TotalCount);
}
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 IgnoreSSL parameter to true when you specify runtime parameters.

public static void Main(string[] args)
{
    AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config();
    // Specify HTTPS as the protocol when you initialize the client.
    config.Protocol = "HTTPS";
    config.Endpoint = "ecs.cn-beijing.aliyuncs.com";
    AlibabaCloud.SDK.Ecs20140526.Client client = new AlibabaCloud.SDK.Ecs20140526.Client(config);
    // Create a RuntimeOptions instance and specify runtime parameters. The settings take effect only on the requests that use the RuntimeOptions instance.
    RuntimeOptions runtimeOptions = new RuntimeOptions();
    // Disable certificate verification.
    runtimeOptions.IgnoreSSL = true;

    DescribeInstancesRequest request = new DescribeInstancesRequest();
    // Process the HTTPS request to serialize the returned results into a response object in the SDK based on the core library.
    var response = client.DescribeInstancesWithOptions(request, runtimeOptions);
    System.Console.WriteLine(response.Body.TotalCount);
}