HTTPS request configuration
Configure HTTPS protocol settings and SSL/TLS parameters for secure communication in the Java (asynchronous) SDK.
The Java (asynchronous) SDK uses HTTPS by default to access Alibaba Cloud services. You can set the protocol parameter to HTTP or HTTPS. We recommend HTTPS for secure data transmission.
Configure the protocol as follows:
AsyncClient client = AsyncClient.builder()
.credentialsProvider(credentialProvider) // The implementation of credentialProvider is omitted.
.overrideConfiguration(
ClientOverrideConfiguration.create()
.setEndpointOverride("<ENDPOINT>") // The service endpoint of the Alibaba Cloud product.
.setProtocol("https") // Set the request protocol. The default value is https.
)
.build();
When you use HTTPS to call an OpenAPI operation, you can configure the following SSL/TLS parameters to enhance security or adapt to special network environments:
|
Configuration parameter |
Description |
|
x509TrustManagers |
A custom CA certificate trust manager of type |
|
keyManagers |
A client key manager of type |
|
ignoreSSL |
Whether to skip SSL/TLS certificate validation. Default: Important
Keep the default value in production environments to ensure secure communication. You can temporarily skip validation for debugging or testing in non-production environments. |
|
hostnameVerifier |
A custom HTTPS hostname verifier. If not configured, the system uses Java's default logic, which checks whether the server hostname matches the domain name in the certificate. Implement custom logic for specific validation requirements, such as handling internal hostnames or specific IP addresses. |
Configure these parameters based on your security requirements and network environment.
Modifying SSL/TLS validation can compromise communication security. Use caution in production environments.
Sample code:
HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
// When you use the HTTPS protocol, you can configure SSL/TLS parameters.
.x509TrustManagers(null) // Configure a custom CA certificate trust manager. This parameter is optional.
.keyManagers(null) // Configure a client key manager. This parameter is optional.
.ignoreSSL(false) // Specify whether to skip certificate validation. The default value is false. This parameter is optional.
.hostnameVerifier(null) // A custom HTTPS hostname validation rule. You must implement javax.net.ssl.HostnameVerifier. This parameter is optional.
.build();
AsyncClient client = AsyncClient.builder()
.credentialsProvider(credentialProvider) // The implementation of credentialProvider is omitted.
.httpClient(httpClient)
.overrideConfiguration(
ClientOverrideConfiguration.create()
.setEndpointOverride("<ENDPOINT>") // The service endpoint of the Alibaba Cloud product.
.setProtocol("https")
)
.build();