All Products
Search
Document Center

Alibaba Cloud SDK:Configure an HTTPS request

Last Updated:Jul 02, 2024

This topic describes how to configure an HTTPS request in Alibaba Cloud SDK V2.0 for Java.

Alibaba Cloud SDK V2.0 allows you to specify the protocol over which API requests are sent in the Config object. We recommend that you send API requests over HTTPS. If you do not specify a protocol, API requests are sent over HTTPS by default.

public static void main(String[] args) throws Exception {
    com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
    // Specify HTTPS as the protocol when you initialize the client.
    config.setProtocol("HTTPS");
    com.aliyun.ecs20140526.Client client = new com.aliyun.ecs20140526.Client(config);

    com.aliyun.ecs20140526.models.DescribeRegionsRequest describeRegionsRequest = new com.aliyun.ecs20140526.models.DescribeRegionsRequest();

    client.describeRegions(describeRegionsRequest);
}
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) throws Exception {
    com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
    // Specify HTTPS as the protocol when you initialize the client.
    config.setProtocol("HTTPS");
    com.aliyun.ecs20140526.Client client = new com.aliyun.ecs20140526.Client(config);

    // Create a RuntimeOptions instance and specify runtime parameters. The settings take effect only on the requests that use the RuntimeOptions instance.
    com.aliyun.teautil.models.RuntimeOptions runtimeOptions = new com.aliyun.teautil.models.RuntimeOptions();
    // Disable certificate verification.
    runtimeOptions.ignoreSSL = true;

    com.aliyun.ecs20140526.models.DescribeRegionsRequest describeRegionsRequest = new com.aliyun.ecs20140526.models.DescribeRegionsRequest();

    client.describeRegionsWithOptions(describeRegionsRequest, runtimeOptions);
}