### Basic Client Configuration Example Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Demonstrates basic client setup with credentials, profile, and HTTP profile settings. ```java Credential cred = new Credential("AKID*****", "secret*****"); ClientProfile profile = new ClientProfile(); profile.setDebug(true); HttpProfile httpProfile = profile.getHttpProfile(); httpProfile.setConnTimeout(30); httpProfile.setReadTimeout(30); httpProfile.setWriteTimeout(30); CvmClient client = new CvmClient(cred, "ap-shanghai", profile); ``` -------------------------------- ### Example: Initialize Client with Region Enum (Commented) Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Provides a commented-out example of how to initialize a client using the Region enum if it were directly available and used. ```java // Or using the Region enum if available // CvmClient client = new CvmClient(cred, Region.AP_SHANGHAI.getRegion()); ``` -------------------------------- ### Complete SDK Configuration Example Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/configuration.md This example demonstrates a comprehensive configuration for the CVM client, including credentials, HTTP settings, proxy configuration, and client profile settings. It shows how to initialize the client and make an API call. ```java import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.cvm.v20170312.CvmClient; import com.tencentcloudapi.cvm.v20170312.models.*; import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.common.profile.Language; public class ConfigurationExample { public static void main(String[] args) throws TencentCloudSDKException { // 1. Configure credentials Credential cred = new Credential( System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY") ); // 2. Configure HTTP settings HttpProfile httpProfile = new HttpProfile(); httpProfile.setReqMethod("POST"); httpProfile.setConnTimeout(30); httpProfile.setReadTimeout(30); httpProfile.setWriteTimeout(30); httpProfile.setEndpoint("cvm.ap-shanghai.tencentcloudapi.com"); // 3. Configure proxy (if needed) httpProfile.setProxyHost("proxy.company.com"); httpProfile.setProxyPort(8080); httpProfile.setProxyUsername("proxyuser"); httpProfile.setProxyPassword("proxypass"); // 4. Configure client profile ClientProfile clientProfile = new ClientProfile(); clientProfile.setSignMethod(ClientProfile.SIGN_TC3_256); clientProfile.setLanguage(Language.EN_US); clientProfile.setDebug(true); clientProfile.setHttpProfile(httpProfile); // 5. Create client CvmClient client = new CvmClient(cred, "ap-shanghai", clientProfile); // 6. Make API call DescribeInstancesRequest req = new DescribeInstancesRequest(); req.setLimit(20L); req.setOffset(0L); DescribeInstancesResponse resp = client.DescribeInstances(req); System.out.println("Total instances: " + resp.getTotalCount()); } } ``` -------------------------------- ### Install All Products SDK via Maven Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/README.md Use this Maven dependency to install the entire Tencent Cloud SDK for Java. This includes all product SDKs and is recommended unless you have strict size constraints. ```xml com.tencentcloudapi tencentcloud-sdk-java 3.1.1000 ``` -------------------------------- ### SDK Log Output Example (commons-logging) Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/README.md Example of log output from the Tencent Cloud Java SDK using commons-logging, showing request and response details. ```text 九月 10, 2020 5:14:30 下午 com.tencentcloudapi.cvm.v20170312.CvmClient info 信息: send request, request url: https://cvm.ap-shanghai.tencentcloudapi.com/?Nonce=367595572&Action=DescribeInstances&Filters.0.Values.1=ap-shanghai-2&Version=2017-03-12&Filters.0.Values.0=ap-shanghai-1&SecretId=AKIDziAMHwiVO0LPCizu61e1iCQP7YiaOX7Q&Filters.0.Name=zone&RequestClient=SDK_JAVA_3.1.129&Region=ap-shanghai&SignatureMethod=HmacSHA256&Timestamp=1599729270&Signature=DcGRPdquMZZRPj1NFXP5bsOGnRlaT2KXy7aegNhZa00%3D. request headers information: 九月 10, 2020 5:14:32 下午 com.tencentcloudapi.cvm.v20170312.CvmClient info 信息: recieve response, response url: https://cvm.ap-shanghai.tencentcloudapi.com/?Nonce=367595572&Action=DescribeInstances&Filters.0.Values.1=ap-shanghai-2&Version=2017-03-12&Filters.0.Values.0=ap-shanghai-1&SecretId=AKIDziAMHwiVO0LPCizu61e1iCQP7YiaOX7Q&Filters.0.Name=zone&RequestClient=SDK_JAVA_3.1.129&Region=ap-shanghai&SignatureMethod=HmacSHA256&Timestamp=1599729270&Signature=DcGRPdquMZZRPj1NFXP5bsOGnRlaT2KXy7aegNhZa00%3D, response headers: Server: nginx;Date: Thu, 10 Sep 2020 09:14:32 GMT;Content-Type: application/json;Content-Length: 103;Connection: keep-alive;OkHttp-Selected-Protocol: http/1.1;OkHttp-Sent-Millis: 1599729271230;OkHttp-Received-Millis: 1599729272020;,response body information: com.squareup.okhttp.internal.http.RealResponseBody@8646db9 ``` -------------------------------- ### Install Specific Product SDK via Maven Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/README.md Use this Maven dependency to install the SDK for a specific Tencent Cloud product. Replace '指定产品包名' with the actual product package name (e.g., 'cvm'). ```xml com.tencentcloudapi tencentcloud-sdk-java-指定产品包名 3.1.1000 ``` -------------------------------- ### Example: Initialize Client with Region String Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Demonstrates initializing a client (e.g., CvmClient) by providing the region code as a string. ```java // Using region code as string CvmClient client = new CvmClient(cred, "ap-shanghai"); ``` -------------------------------- ### Add Request Parameters Example Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/common-client.md Demonstrates how to add multiple request parameters using the putData method. ```java CommonRequest req = new CommonRequest(); req.putData("InstanceIds.0", "ins-123456"); req.putData("Limit", "20"); req.putData("Offset", "0"); ``` -------------------------------- ### CVM Example Types Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Examples of service-specific request, response, and data model types for the CVM service. ```APIDOC ## Service-Specific Types - CVM Example ### Requests - `com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest` - `com.tencentcloudapi.cvm.v20170312.models.RunInstancesRequest` - `com.tencentcloudapi.cvm.v20170312.models.TerminateInstancesRequest` ### Responses - `com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse` - `com.tencentcloudapi.cvm.v20170312.models.RunInstancesResponse` - `com.tencentcloudapi.cvm.v20170312.models.TerminateInstancesResponse` ### Data Models - `com.tencentcloudapi.cvm.v20170312.models.Instance` - `com.tencentcloudapi.cvm.v20170312.models.Image` - `com.tencentcloudapi.cvm.v20170312.models.SecurityGroup` - `com.tencentcloudapi.cvm.v20170312.models.Filter` ``` -------------------------------- ### JSON Conversion Example for Request and Response Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Provides a complete example of converting a request object to a JSON string for inspection and printing the JSON string of a response object. ```java // Create request object DescribeInstancesRequest req = new DescribeInstancesRequest(); req.setLimit(10L); req.setOffset(0L); // Convert to JSON for inspection String jsonReq = AbstractModel.toJsonString(req); // Output: {"Limit":10,"Offset":0} // After API call, get response DescribeInstancesResponse resp = client.DescribeInstances(req); // Convert response to JSON String jsonResp = AbstractModel.toJsonString(resp); System.out.println(jsonResp); ``` -------------------------------- ### Example: Set Custom HTTP Headers Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Shows how to create a map of custom headers and attach them to a request object using SetHeader. ```java DescribeInstancesRequest req = new DescribeInstancesRequest(); Map headers = new HashMap<>(); headers.put("X-TC-TraceId", "trace-id-value"); req.SetHeader(headers); ``` -------------------------------- ### Initialize Credential from Environment Variables Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/credential.md Example of initializing a Credential object by reading Secret ID and Secret Key from environment variables. ```java Credential cred = new Credential( System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY") ); ``` -------------------------------- ### Service Client Classes Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/INDEX.md Details on how to use service client classes, with an example for CVMClient and a list of other available clients. ```APIDOC ## Service Client Classes All service clients extend `AbstractClient` and follow a consistent pattern. ### Example: CvmClient - **Service**: Elastic Cloud Compute (CVM) - **Package Version**: v20170312 (2017-03-12) - **Constructors**: `CvmClient(Credential, String)`, `CvmClient(Credential, String, ClientProfile)` - **API Methods**: - `AllocateHosts(AllocateHostsRequest)` → `AllocateHostsResponse` - `AssociateInstancesKeyPairs(AssociateInstancesKeyPairsRequest)` → `AssociateInstancesKeyPairsResponse` - `AssociateSecurityGroups(AssociateSecurityGroupsRequest)` → `AssociateSecurityGroupsResponse` - `ConfigureChcAssistVpc(ConfigureChcAssistVpcRequest)` → `ConfigureChcAssistVpcResponse` - `DescribeInstances(DescribeInstancesRequest)` → `DescribeInstancesResponse` - `RunInstances(RunInstancesRequest)` → `RunInstancesResponse` - `TerminateInstances(TerminateInstancesRequest)` → `TerminateInstancesResponse` ### Other Service Clients Available for services including: SlbClient, CdbClient, VpcClient, CamClient, StsClient, MonitorClient, and over 200 more. ``` -------------------------------- ### Map Type Examples Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Shows how to use HashMaps for storing key-value pairs, including simple string maps and maps with mixed object types for dynamic data. ```java Map tags = new HashMap<>(); tags.put("key", "value"); Map data = new HashMap<>(); data.put("field1", "value1"); data.put("field2", 123); ``` -------------------------------- ### Array Type Examples Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Illustrates the declaration and initialization of arrays for primitive types (String, Long) and object types (Instance). ```java String[] instanceIds = new String[]{"ins-123456", "ins-789012"}; Long[] ids = new Long[]{1L, 2L, 3L}; Instance[] instances = new Instance[]{instance1, instance2}; ``` -------------------------------- ### CVM Service Example Types Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Illustrates the common request, response, and data model types available for the CVM service. ```java // Requests com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest com.tencentcloudapi.cvm.v20170312.models.RunInstancesRequest com.tencentcloudapi.cvm.v20170312.models.TerminateInstancesRequest // Responses com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse com.tencentcloudapi.cvm.v20170312.models.RunInstancesResponse com.tencentcloudapi.cvm.v20170312.models.TerminateInstancesResponse // Data Models com.tencentcloudapi.cvm.v20170312.models.Instance com.tencentcloudapi.cvm.v20170312.models.Image com.tencentcloudapi.cvm.v20170312.models.SecurityGroup com.tencentcloudapi.cvm.v20170312.models.Filter ``` -------------------------------- ### JSON Conversion Example Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Demonstrates how to convert request objects to JSON strings for inspection and how to handle response objects after an API call. ```APIDOC ## JSON Conversion Example ### Request Conversion ```java // Create request object DescribeInstancesRequest req = new DescribeInstancesRequest(); req.setLimit(10L); req.setOffset(0L); // Convert to JSON for inspection String jsonReq = AbstractModel.toJsonString(req); // Output: {"Limit":10,"Offset":0} ``` ### Response Conversion ```java // After API call, get response DescribeInstancesResponse resp = client.DescribeInstances(req); // Convert response to JSON String jsonResp = AbstractModel.toJsonString(resp); System.out.println(jsonResp); ``` ``` -------------------------------- ### Simplified DescribeInstances API Call Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/README.md A simplified Java example demonstrating how to call the DescribeInstances API using environment variables for credentials. It's recommended to use environment variables or configuration files for security instead of hardcoding secrets. ```java import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.cvm.v20170312.CvmClient; import com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest; import com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse; public class DescribeInstances { public static void main(String[] args) { try { // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。 // 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。 // Credential cred = new Credential("SecretId", "SecretKey"); Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY")); CvmClient client = new CvmClient(cred, "ap-shanghai"); DescribeInstancesRequest req = new DescribeInstancesRequest(); DescribeInstancesResponse resp = client.DescribeInstances(req); System.out.println(DescribeInstancesResponse.toJsonString(resp)); } catch (TencentCloudSDKException e) { System.out.println(e.toString()); } } } ``` -------------------------------- ### Example: Set Language Profile Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Shows how to set the desired language for API responses using the Language enum when creating a ClientProfile. ```java ClientProfile profile = new ClientProfile(); profile.setLanguage(Language.EN_US); ``` -------------------------------- ### Initialize CVM Client with Permanent Credentials Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/credential.md Example of initializing a CVM client using permanent API credentials (Secret ID and Secret Key). ```java Credential cred = new Credential("AKID*****", "secret*****"); CvmClient client = new CvmClient(cred, "ap-shanghai"); DescribeInstancesRequest req = new DescribeInstancesRequest(); DescribeInstancesResponse resp = client.DescribeInstances(req); ``` -------------------------------- ### Get Credentials using Configuration File Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/credential-providers.md Reads credentials from the `~/.tencentcloud/credentials` file. Ensure the file exists and is correctly formatted with a `[default]` section containing `secret_id` and `secret_key`. ```java // Create ~/.tencentcloud/credentials with: // [default] // secret_id = AKID***** // secret_key = secret***** ProfileCredentialsProvider provider = new ProfileCredentialsProvider(); Credential cred = provider.getCredentials(); CvmClient client = new CvmClient(cred, "ap-shanghai"); ``` -------------------------------- ### Get Credentials using Environment Variables Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/credential-providers.md Obtains credentials by reading from `TENCENTCLOUD_SECRET_ID` and `TENCENTCLOUD_SECRET_KEY` environment variables. Ensure these variables are set before execution. ```java // Set environment variables: // export TENCENTCLOUD_SECRET_ID=AKID***** // export TENCENTCLOUD_SECRET_KEY=secret***** EnvironmentVariableCredentialsProvider provider = new EnvironmentVariableCredentialsProvider(); Credential cred = provider.getCredentials(); CvmClient client = new CvmClient(cred, "ap-shanghai"); ``` -------------------------------- ### Call DescribeInstances API and get response Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/README.md Calls the DescribeInstances API using the CVM client and receives the response. ```java // 通过client对象调用DescribeInstances方法发起请求。注意请求方法名与请求对象是对应的 // 返回的resp是一个DescribeInstancesResponse类的实例,与请求对象对应 DescribeInstancesResponse resp = client.DescribeInstances(req); ``` -------------------------------- ### Get Credentials from Configuration File Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/credential-providers.md Reads credentials from the default configuration file location (~/.tencentcloud/credentials or c:\\Users\\NAME\\.tencentcloud\\credentials). Ensure the configuration file is correctly formatted and accessible. ```java Credential cred = new ProfileCredentialsProvider().getCredentials(); CvmClient client = new CvmClient(cred, "ap-shanghai"); ``` -------------------------------- ### Calling APIs Without Generated Clients (CAS Example) Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/common-client.md Demonstrates using CommonClient to call APIs for services that do not have a dedicated client generated in the SDK. This provides a fallback mechanism for accessing any Tencent Cloud API. ```java // No CAS client generated yet, use CommonClient Credential cred = new Credential("AKID*****", "secret*****"); CommonClient client = new CommonClient("cas", "2020-01-01", cred, "ap-shanghai"); CommonRequest req = new CommonRequest(); req.setAction("DescribeCertificates"); req.putData("Limit", "20"); String response = client.commonRequest(req, "DescribeCertificates"); ``` -------------------------------- ### Initialize Credential with Ephemeral Credentials (STS) Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/credential.md Example of initializing a Credential object with ephemeral credentials including Secret ID, Secret Key, and a session token. ```java Credential cred = new Credential("AKID*****", "secret*****", "token*****"); // Token expires after some time, but SDK handles it with updater ``` -------------------------------- ### Get Credentials from Configuration File Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/README.md Load Tencent Cloud credentials from a configuration file using the ProfileCredentialsProvider. The file path varies by operating system. ```java Credential cred = new ProfileCredentialsProvider().getCredentials(); ``` -------------------------------- ### Example: Convert Response to JSON String Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Demonstrates how to convert a response object (e.g., DescribeInstancesResponse) into a JSON string using the toJsonString method. ```java DescribeInstancesResponse resp = client.DescribeInstances(req); String json = AbstractModel.toJsonString(resp); System.out.println(json); ``` -------------------------------- ### Basic SDK Usage Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/README.md Demonstrates the basic workflow of setting up credentials, creating a service client, making a request, and handling responses or exceptions. ```java Credential cred = new Credential("AKID*****", "secret*****"); CvmClient client = new CvmClient(cred, "ap-shanghai"); DescribeInstancesRequest req = new DescribeInstancesRequest(); req.setLimit(20L); try { DescribeInstancesResponse resp = client.DescribeInstances(req); System.out.println("Instances: " + resp.getTotalCount()); } catch (TencentCloudSDKException e) { System.err.println("Error: " + e.getMessage()); } ``` -------------------------------- ### ClientProfile Methods Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Methods for getting and setting various client configuration options, including signature method, HTTP profile, payload signing, language, debug mode, and backup endpoint. ```APIDOC ## getSignMethod() ### Description Gets the signature method used for signing API requests. ### Method ```java public String getSignMethod() ``` ### Returns String - The signature method ## setSignMethod(String signMethod) ### Description Sets the signature method for API requests. ### Method ```java public void setSignMethod(String signMethod) ``` ### Parameters #### Path Parameters - **signMethod** (String) - The signature method to use ## getHttpProfile() ### Description Gets the HTTP profile containing timeout and endpoint settings. ### Method ```java public HttpProfile getHttpProfile() ``` ### Returns HttpProfile - The HTTP profile ## setHttpProfile(HttpProfile httpProfile) ### Description Sets the HTTP profile for connection and timeout settings. ### Method ```java public void setHttpProfile(HttpProfile httpProfile) ``` ### Parameters #### Path Parameters - **httpProfile** (HttpProfile) - The HTTP profile to use ## isUnsignedPayload() ### Description Gets whether the request payload is excluded from signing. ### Method ```java public boolean isUnsignedPayload() ``` ### Returns boolean - true if payload is unsigned, false otherwise ## setUnsignedPayload(boolean unsignedPayload) ### Description Sets whether to exclude request payload from signing. Default is false. ### Method ```java public void setUnsignedPayload(boolean unsignedPayload) ``` ### Parameters #### Path Parameters - **unsignedPayload** (boolean) - true to exclude payload from signing ## getLanguage() ### Description Gets the language setting for API responses. ### Method ```java public Language getLanguage() ``` ### Returns Language - The language preference (null if not set) ## setLanguage(Language language) ### Description Sets the language for API responses. Supported: `Language.ZH_CN` or `Language.EN_US`. ### Method ```java public void setLanguage(Language language) ``` ### Parameters #### Path Parameters - **language** (Language) - The language preference ### Example ```java ClientProfile profile = new ClientProfile(); profile.setLanguage(Language.EN_US); CvmClient client = new CvmClient(credential, "ap-shanghai", profile); ``` ## isDebug() ### Description Gets whether debug mode is enabled for request/response logging. ### Method ```java public boolean isDebug() ``` ### Returns boolean - true if debugging is enabled ## setDebug(boolean debug) ### Description Enables or disables debug logging of requests and responses. ### Method ```java public void setDebug(boolean debug) ``` ### Parameters #### Path Parameters - **debug** (boolean) - true to enable debug logging ### Example ```java ClientProfile profile = new ClientProfile(); profile.setDebug(true); // SDK will now log HTTP requests and responses ``` ## getBackupEndpoint() ### Description Gets the backup endpoint for region failover. ### Method ```java public String getBackupEndpoint() ``` ### Returns String - The backup endpoint (null if not set) ``` -------------------------------- ### Get Credentials using Default Chain Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/credential-providers.md Attempts to obtain credentials from multiple sources in order (environment variables, configuration file, instance role, OIDC). Returns the first successful source. This is the recommended method for automatic credential discovery. ```java public Credential getCredentials() throws TencentCloudSDKException ``` ```java // Automatically tries multiple credential sources Credential cred = new DefaultCredentialsProvider().getCredentials(); CvmClient client = new CvmClient(cred, "ap-shanghai"); ``` -------------------------------- ### Describe CVM Instances with Java SDK Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/README.md This snippet shows how to initialize the CVM client, set up HTTP and client profiles, and make a request to describe instances. It includes configuration for proxy, timeouts, signature method, and language. It also demonstrates how to filter instances by zone and print the response. ```java import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.exception.TencentCloudSDKException; // 导入对应产品模块的client import com.tencentcloudapi.cvm.v20170312.CvmClient; // 导入要请求接口对应的request response类 import com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest; import com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse; import com.tencentcloudapi.cvm.v20170312.models.Filter; //导入可选配置类 import com.tencentcloudapi.common.profile.ClientProfile; import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.common.profile.Language; public class DescribeInstances { public static void main(String[] args) { try { // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId,SecretKey。 // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。 // 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。 // Credential cred = new Credential("SecretId", "SecretKey"); Credential cred = new Credential(System.getenv("TENCENTCLOUD_SECRET_ID"), System.getenv("TENCENTCLOUD_SECRET_KEY")); // 实例化一个http选项,可选的,没有特殊需求可以跳过 HttpProfile httpProfile = new HttpProfile(); // 从3.0.96版本开始, 单独设置 HTTP 代理 // httpProfile.setProxyHost("真实代理ip"); // httpProfile.setProxyPort(真实代理端口); httpProfile.setReqMethod("GET"); // get请求(默认为post请求) httpProfile.setConnTimeout(30); // 请求连接超时时间,单位为秒(默认60秒) httpProfile.setWriteTimeout(30); // 设置写入超时时间,单位为秒(默认0秒) httpProfile.setReadTimeout(30); // 设置读取超时时间,单位为秒(默认0秒) httpProfile.setEndpoint("cvm.ap-shanghai.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入) // 实例化一个client选项,可选的,没有特殊需求可以跳过 ClientProfile clientProfile = new ClientProfile(); clientProfile.setSignMethod(ClientProfile.SIGN_TC3_256); // 指定签名算法(默认为TC3-HMAC-SHA256) // 自3.1.80版本开始,SDK 支持打印日志。 clientProfile.setHttpProfile(httpProfile); clientProfile.setDebug(true); // 从3.1.16版本开始,支持设置公共参数 Language, 默认不传,选择(ZH_CN or EN_US) clientProfile.setLanguage(Language.EN_US); // 实例化要请求产品(以cvm为例)的client对象,clientProfile是可选的 CvmClient client = new CvmClient(cred, "ap-shanghai", clientProfile); // 实例化一个cvm实例信息查询请求对象,每个接口都会对应一个request对象。 DescribeInstancesRequest req = new DescribeInstancesRequest(); // 填充请求参数,这里request对象的成员变量即对应接口的入参 // 您可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义 Filter respFilter = new Filter(); // 创建Filter对象, 以zone的维度来查询cvm实例 respFilter.setName("zone"); respFilter.setValues(new String[] { "ap-shanghai-1", "ap-shanghai-2" }); req.setFilters(new Filter[] { respFilter }); // Filters 是成员为Filter对象的列表 // 通过client对象调用DescribeInstances方法发起请求。注意请求方法名与请求对象是对应的 // 返回的resp是一个DescribeInstancesResponse类的实例,与请求对象对应 DescribeInstancesResponse resp = client.DescribeInstances(req); // 输出json格式的字符串回包 System.out.println(DescribeInstancesResponse.toJsonString(resp)); // 也可以取出单个值。 // 您可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义 System.out.println(resp.getTotalCount()); } catch (TencentCloudSDKException e) { System.out.println(e.toString()); } } } ``` -------------------------------- ### Create and Use Request Objects Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/README.md Demonstrates how to instantiate request objects and set API parameters for service calls. Use setters to populate request fields before sending them to the client. ```java DescribeInstancesRequest req = new DescribeInstancesRequest(); req.setInstanceIds(new String[]{"ins-123"}); req.setLimit(20L); req.setOffset(0L); ``` -------------------------------- ### getHostnameVerifier() Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Gets the custom hostname verifier. Returns null if not set. ```APIDOC ## getHostnameVerifier() ### Description Gets the custom hostname verifier. ### Returns HostnameVerifier - The hostname verifier (null if not set) ``` -------------------------------- ### getProxyPassword() Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Gets the proxy authentication password. Returns null if not set. ```APIDOC ## getProxyPassword() ### Description Gets the proxy authentication password. ### Returns String - The password (null if not set) ``` -------------------------------- ### getProxyUsername() Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Gets the proxy authentication username. Returns null if not set. ```APIDOC ## getProxyUsername() ### Description Gets the proxy authentication username. ### Returns String - The username (null if not set) ``` -------------------------------- ### getProxyHost() Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Gets the HTTP proxy hostname. Returns null if not set. ```APIDOC ## getProxyHost() ### Description Gets the HTTP proxy hostname. ### Returns String - The proxy hostname (null if not set) ``` -------------------------------- ### CommonClient with Custom Configuration Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/common-client.md Shows how to initialize CommonClient with a custom ClientProfile to configure settings like connection timeout and debug mode. This allows for fine-tuning the client's behavior. ```java Credential cred = new Credential("AKID*****", "secret*****"); ClientProfile profile = new ClientProfile(); profile.setDebug(true); profile.getHttpProfile().setConnTimeout(30); CommonClient client = new CommonClient( "cvm", "2017-03-12", cred, "ap-shanghai", profile ); CommonRequest req = new CommonRequest(); req.setAction("DescribeInstances"); req.putData("Limit", "10"); String response = client.commonRequest(req, "DescribeInstances"); ``` -------------------------------- ### getX509TrustManager() Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Gets the custom X.509 trust manager. Returns null if not set. ```APIDOC ## getX509TrustManager() ### Description Gets the custom X.509 trust manager. ### Returns X509TrustManager - The trust manager (null if not set) ``` -------------------------------- ### getSslSocketFactory() Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Gets the custom SSL socket factory. Returns null if not set. ```APIDOC ## getSslSocketFactory() ### Description Gets the custom SSL socket factory. ### Returns SSLSocketFactory - The SSL socket factory (null if not set) ``` -------------------------------- ### getProxyPort() Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Gets the HTTP proxy port. Returns the proxy port number. ```APIDOC ## getProxyPort() ### Description Gets the HTTP proxy port. ### Returns int - The proxy port ``` -------------------------------- ### Configure SDK Client Profile Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/README.md Explains how to customize SDK behavior using `ClientProfile` and `HttpProfile`. Set debug mode, connection timeouts, and proxy settings for network requests. ```java ClientProfile profile = new ClientProfile(); profile.setDebug(true); HttpProfile httpProfile = profile.getHttpProfile(); httpProfile.setConnTimeout(30); httpProfile.setProxyHost("proxy.example.com"); httpProfile.setProxyPort(8080); CvmClient client = new CvmClient(cred, "ap-shanghai", profile); ``` -------------------------------- ### Get API Action Name Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/common-client.md Retrieves the name of the API action being called. ```java public String getAction() ``` -------------------------------- ### RunInstances API Method Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/service-clients.md Creates one or more CVM instances with specified configurations. Use this method to launch new virtual machines. ```java public RunInstancesResponse RunInstances(RunInstancesRequest req) throws TencentCloudSDKException ``` ```java RunInstancesRequest req = new RunInstancesRequest(); req.setImageId("img-1234567"); req.setInstanceType("t3.medium"); req.setInstanceCount(1L); req.setInstanceChargeType("POSTPAID_BY_HOUR"); req.setVpcId("vpc-abcd1234"); req.setSubnetId("subnet-efgh5678"); RunInstancesResponse resp = client.RunInstances(req); for (String id : resp.getInstanceIdSet()) { System.out.println("Created instance: " + id); } ``` -------------------------------- ### Getting the exception message Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/exceptions.md Retrieve the descriptive error message associated with the TencentCloudSDKException. ```java try { client.DescribeInstances(req); } catch (TencentCloudSDKException e) { System.err.println(e.getMessage()); } ``` -------------------------------- ### getHttpClient() Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Gets the custom HTTP client for advanced users. Returns null if not set. ```APIDOC ## getHttpClient() ### Description Gets the custom HTTP client for advanced users. ### Returns Object - The HTTP client object (null if not set) ``` -------------------------------- ### Create CommonClient with Default Profile Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/common-client.md Instantiate a CommonClient using product name, API version, credentials, and region with default client profile settings. ```java Credential cred = new Credential("AKID*****", "secret*****"); CommonClient client = new CommonClient("cvm", "2017-03-12", cred, "ap-shanghai"); ``` -------------------------------- ### getApigwEndpoint() Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Gets the API Gateway endpoint if using API Gateway. Returns null if not set. ```APIDOC ## getApigwEndpoint() ### Description Gets the API Gateway endpoint if using API Gateway. ### Returns String - The API Gateway endpoint (null if not set) ``` -------------------------------- ### Use Environment Variables for Credentials Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/README.md Demonstrates how to retrieve credentials using the `EnvironmentVariableCredentialsProvider`. ```java Credential cred = new EnvironmentVariableCredentialsProvider().getCredentials(); CvmClient client = new CvmClient(cred, "ap-shanghai"); ``` -------------------------------- ### Get Proxy Password Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the password configured for proxy authentication. Returns null if not set. ```java public String getProxyPassword() ``` -------------------------------- ### Get Proxy Username Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the username configured for proxy authentication. Returns null if not set. ```java public String getProxyUsername() ``` -------------------------------- ### Dynamic Product Selection for API Calls Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/common-client.md Shows how to dynamically select the product, version, and action for an API call. This is useful for creating flexible clients that can interact with different services. ```java String product = "cvm"; String version = "2017-03-12"; String action = "DescribeInstances"; Credential cred = new Credential("AKID*****", "secret*****"); CommonClient client = new CommonClient(product, version, cred, "ap-shanghai"); CommonRequest req = new CommonRequest(); req.setAction(action); req.putData("Limit", "10"); String response = client.commonRequest(req, action); System.out.println(response); ``` -------------------------------- ### Getting the cause of the exception Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/exceptions.md Retrieve the underlying exception if the TencentCloudSDKException was created by wrapping another throwable. ```java try { client.DescribeInstances(req); } catch (TencentCloudSDKException e) { Throwable cause = e.getCause(); if (cause != null) { System.err.println("Underlying cause: " + cause.getMessage()); } } ``` -------------------------------- ### Configure Credentials from Configuration File Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/configuration.md Load credentials from the default Tencent Cloud credentials file located at ~/.tencentcloud/credentials or c:\.tencentcloud\credentials. The file uses an INI format. ```ini [default] secret_id = AKID***** secret_key = secret***** ``` ```java ProfileCredentialsProvider provider = new ProfileCredentialsProvider(); Credential credential = provider.getCredentials(); ``` -------------------------------- ### Set Environment Variables for Credentials Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/README.md Shows how to set environment variables for TENCENTCLOUD_SECRET_ID and TENCENTCLOUD_SECRET_KEY to authenticate. ```bash export TENCENTCLOUD_SECRET_ID=your-secret-id export TENCENTCLOUD_SECRET_KEY=your-secret-key ``` -------------------------------- ### Error Codes Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/INDEX.md Categorized list of common error codes encountered when using the SDK, with examples for each category. ```APIDOC ## Error Codes ### Categories - **Authentication/Authorization**: `UnauthorizedOperation`, `AuthFailure`, `InvalidParameterValue.InvalidSecretId` - **Resource Not Found**: `ResourceNotFound.InstanceNotFound`, `ResourceNotFound.ImageNotFound` - **Invalid Parameters**: `InvalidParameter`, `InvalidParameterValue`, `MissingParameter` - **Resource State**: `InvalidInstance.NotSupported`, `OperationDenied`, `ResourceInUse` - **Rate Limiting**: `LimitExceeded.ResourceLimitExceeded`, `RequestLimitExceeded.IPLimitExceeded` - **Internal Errors**: `InternalError`, `ServiceUnavailable` ``` -------------------------------- ### Get API Gateway Endpoint Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the API Gateway endpoint if configured. Returns null if not set. ```java public String getApigwEndpoint() ``` -------------------------------- ### Get HTTP Proxy Port Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the configured HTTP proxy port. Returns the port number. ```java public int getProxyPort() ``` -------------------------------- ### Get HTTP Proxy Hostname Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the configured HTTP proxy hostname. Returns null if not set. ```java public String getProxyHost() ``` -------------------------------- ### Get Updater Callback Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/credential.md Retrieves the credential updater callback function, if one has been set on the Credential object. ```java public Updater getUpdater() ``` -------------------------------- ### Example: Add Customized Parameter Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md Illustrates how to add a custom field and its value to a CommonRequest object using putCustomizedParam. ```java CommonRequest req = new CommonRequest(); req.putCustomizedParam("CustomField", "value"); ``` -------------------------------- ### Configure Credentials using Assume Role (STS) Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/configuration.md Create STS credentials by providing Secret ID, Secret Key, the role's ARN, and a session name. ```java Credential credential = new STSCredential( "AKID*****", "secret*****", "acs::cam::uin/1234567890:role/RoleName", "session-name" ); ``` -------------------------------- ### Create ClientProfile with Custom HTTP Profile Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Initializes a ClientProfile with both a specific signature method and a custom HttpProfile for detailed network control. ```java public ClientProfile(String signMethod, HttpProfile httpProfile) ``` -------------------------------- ### Get Hostname Verifier Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the custom hostname verifier used for SSL/TLS verification. Returns null if not set. ```java public HostnameVerifier getHostnameVerifier() ``` -------------------------------- ### Configuration Options Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/INDEX.md Details on various configuration options for the SDK, including ClientProfile, HttpProfile, and environment variables. ```APIDOC ## Configuration Options ### ClientProfile Options - `signMethod`, `httpProfile`, `unsignedPayload`, `language`, `debug`, `backupEndpoint` ### HttpProfile Options - `reqMethod`, `endpoint`, `rootDomain`, `protocol`, `readTimeout`, `writeTimeout`, `connTimeout` - `proxyHost`, `proxyPort`, `proxyUsername`, `proxyPassword` - `sslSocketFactory`, `x509TrustManager`, `hostnameVerifier`, `httpClient`, `apigwEndpoint` ### Environment Variables - `TENCENTCLOUD_SECRET_ID` - `TENCENTCLOUD_SECRET_KEY` - `TENCENTCLOUD_TOKEN` (optional) ``` -------------------------------- ### Getting the request ID Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/exceptions.md Obtain the request ID from a TencentCloudSDKException, which is crucial for debugging and providing to support for issue resolution. ```java try { client.DescribeInstances(req); } catch (TencentCloudSDKException e) { System.out.println("Request ID: " + e.getRequestId()); // Provide this ID to Tencent Cloud support for debugging } ``` -------------------------------- ### Filter Type Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/types.md An example of a data model type (`Filter`) used in query requests to filter results by field and value. ```APIDOC ## Filter Type (Example) ### Description Used in query requests to filter results by field and value. ### Class Signature ```java public class Filter extends AbstractModel ``` ### Fields - **Name** (`String`): The field name to filter by. - **Values** (`String[]`): The values to match. ### Example ```java Filter filter = new Filter(); filter.setName("zone"); filter.setValues(new String[]{"ap-shanghai-1", "ap-shanghai-2"}); DescribeInstancesRequest req = new DescribeInstancesRequest(); req.setFilters(new Filter[]{filter}); ``` ``` -------------------------------- ### Configure Client with Proxy Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Use this snippet to configure the client to use a proxy server. Ensure the proxy host, port, and authentication details are correctly set. ```java Credential cred = new Credential("AKID*****", "secret*****"); ClientProfile profile = new ClientProfile(); HttpProfile httpProfile = profile.getHttpProfile(); httpProfile.setProxyHost("proxy.example.com"); httpProfile.setProxyPort(8080); httpProfile.setProxyUsername("user"); httpProfile.setProxyPassword("pass"); CvmClient client = new CvmClient(cred, "ap-shanghai", profile); ``` -------------------------------- ### Configure Credentials from Environment Variables Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/configuration.md Use EnvironmentVariableCredentialsProvider to automatically load credentials from TENCENTCLOUD_SECRET_ID and TENCENTCLOUD_SECRET_KEY environment variables. ```bash export TENCENTCLOUD_SECRET_ID=AKID***** export TENCENTCLOUD_SECRET_KEY=secret***** ``` ```java EnvironmentVariableCredentialsProvider provider = new EnvironmentVariableCredentialsProvider(); Credential credential = provider.getCredentials(); ``` -------------------------------- ### Create and configure DescribeInstancesRequest Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/README.md Instantiates a DescribeInstancesRequest and sets filters to query CVM instances by zone. ```java DescribeInstancesRequest req = new DescribeInstancesRequest(); // 填充请求参数,这里request对象的成员变量即对应接口的入参 // 您可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义 Filter respFilter = new Filter(); // 创建Filter对象, 以zone的维度来查询cvm实例 respFilter.setName("zone"); respFilter.setValues(new String[] { "ap-shanghai-1", "ap-shanghai-2" }); req.setFilters(new Filter[] { respFilter }); // Filters 是成员为Filter对象的列表 ``` -------------------------------- ### Initialize Credentials Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/service-clients.md Initialize your Tencent Cloud credentials using your SecretId and SecretKey. Alternatively, you can use credential providers for more dynamic credential management. ```java Credential cred = new Credential("AKID*****", "secret*****"); // Or use credential providers // Credential cred = new DefaultCredentialsProvider().getCredentials(); ``` -------------------------------- ### Get Custom HTTP Client Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the custom HTTP client object for advanced control. Returns null if not set. ```java public Object getHttpClient() ``` -------------------------------- ### Create CommonClient with Custom Profile Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/common-client.md Instantiate a CommonClient with custom client profile configuration, including options like debug mode. ```java Credential cred = new Credential("AKID*****", "secret*****"); ClientProfile profile = new ClientProfile(); profile.setDebug(true); CommonClient client = new CommonClient( "cvm", "2017-03-12", cred, "ap-shanghai", profile ); ``` -------------------------------- ### Configure Credentials Directly Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/configuration.md Instantiate a Credential object directly using your Secret ID and Secret Key. ```java Credential credential = new Credential("AKID*****", "secret*****"); ``` -------------------------------- ### Get X509 Trust Manager Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the custom X.509 trust manager used for certificate validation. Returns null if not set. ```java public X509TrustManager getX509TrustManager() ``` -------------------------------- ### Create HttpProfile with Default Settings Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Creates an HttpProfile instance with default settings for HTTP communication. Default settings include HTTPS, POST method, and a 60-second connection timeout. ```java HttpProfile httpProfile = new HttpProfile(); httpProfile.setConnTimeout(30); ClientProfile profile = new ClientProfile(ClientProfile.SIGN_TC3_256, httpProfile); ``` -------------------------------- ### Configure Client with Region Failover Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md This snippet demonstrates how to configure region failover for a client. It involves setting a backup endpoint and a circuit breaker for resilience. ```java ClientProfile profile = new ClientProfile(); profile.setBackupEndpoint("ap-guangzhou.tencentcloudapi.com"); CircuitBreaker.Setting setting = new CircuitBreaker.Setting(); setting.maxFailNum = 6; setting.maxFailPercentage = 0.8f; CircuitBreaker breaker = new CircuitBreaker(setting); CvmClient client = new CvmClient(cred, "ap-shanghai", profile); client.setRegionBreaker(breaker); ``` -------------------------------- ### Get SSL Socket Factory Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the custom SSL socket factory for advanced SSL/TLS configuration. Returns null if not set. ```java public SSLSocketFactory getSslSocketFactory() ``` -------------------------------- ### ClientProfile Constructors Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md The ClientProfile class provides constructors to initialize client configurations with default or custom settings for signature methods and HTTP profiles. ```APIDOC ## ClientProfile() ### Description Creates a ClientProfile with default settings: TC3-HMAC-SHA256 signature and default HTTP profile. ### Constructor ```java public ClientProfile() ``` ### Example ```java ClientProfile profile = new ClientProfile(); CvmClient client = new CvmClient(credential, "ap-shanghai", profile); ``` ## ClientProfile(String signMethod) ### Description Creates a ClientProfile with specified signature method and default HTTP profile. ### Constructor ```java public ClientProfile(String signMethod) ``` ### Parameters #### Path Parameters - **signMethod** (String) - Required - Signature method: "HmacSHA1", "HmacSHA256", or "TC3-HMAC-SHA256" ### Example ```java ClientProfile profile = new ClientProfile(ClientProfile.SIGN_TC3_256); ``` ## ClientProfile(String signMethod, HttpProfile httpProfile) ### Description Creates a ClientProfile with specified signature method and HTTP profile. ### Constructor ```java public ClientProfile(String signMethod, HttpProfile httpProfile) ``` ### Parameters #### Path Parameters - **signMethod** (String) - Required - Signature method: "HmacSHA1", "HmacSHA256", or "TC3-HMAC-SHA256" - **httpProfile** (HttpProfile) - Required - HTTP configuration settings ``` -------------------------------- ### getReqMethod Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/client-configuration.md Retrieves the HTTP request method (GET or POST) currently configured for the profile. This helps in understanding how requests will be sent to the API. ```APIDOC ## getReqMethod() ### Description Gets the HTTP request method (GET or POST). ### Method ```java public String getReqMethod() ``` ### Returns String - The request method ``` -------------------------------- ### Get Secret Key Source: https://github.com/tencentcloud/tencentcloud-sdk-java/blob/master/_autodocs/api-reference/credential.md Retrieves the Secret Key from the Credential object. If an updater is configured, this action may trigger a credential refresh. ```java public String getSecretKey() ```